Java multithreading, main thread has stopped why? -
this question has reply here:
when phone call java's thread.run() instead of thread.start()? 14 answersi trying create separate thread lwjgl's display.update(), main thread sleeping or stopped while sec thread running, how can create both threads execute simultaneously?
public window(int width, int height, string title){ } @override public void run() { seek { display.setdisplaymode(new displaymode(800, 600)); display.create(); } grab (lwjglexception e) { e.printstacktrace(); } while(!display.iscloserequested()){ display.update(); main.render(); } display.destroy(); }
}
public static void main(string[] args) { //to moved window window = new window(100, 100, "1"); thread windowthread = new thread(window); windowthread.run(); system.out.print("i workign, please show me!"); } public static void render(){ system.out.println("hello there!"); }
change this,
thread windowthread = new thread(window); windowthread.run();
as,
thread windowthread = new thread(window); windowthread.start();
from here
the separate start() , run() methods in thread class provide 2 ways create threaded programs. start() method starts execution of new thread , calls run() method. start() method returns , new thread continues until run() method returns.
the thread class' run() method nothing, sub-classes should override method code execute in sec thread. if thread instantiated runnable argument, thread's run() method executes run() method of runnable object in new thread instead.
depending on nature of threaded program, calling thread run() method straight can give same output calling via start() method, in latter case code executed in new thread.
java multithreading lwjgl
No comments:
Post a Comment