Java code Multiple Thread, Wait to start other -
i trying find out, after complete first thread start second thread, after complete second thread start third thread, please me!!
here code:
public class wait { /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub system.out.println("first thread"); createtheard2(); } public static void createtheard2() { try { system.out.println("second thread"); } catch(exception error1) { error1.printstacktrace(); } createtheard3(); } public static void createtheard3() { try { system.out.println("third thread"); } catch(exception error1) { error1.printstacktrace(); } } }
after complete first thread, start second thread, after complete second thread, start third thread, please me!! thanks!!
implement runnable
public class threaddemo implements runnable { public void run() { //do need } }
use join wait while thread completed.
thread t1 = new thread(new threaddemo()); // call run() function t1.start(); // waits thread die t1.join(); thread t2 = new thread(new threaddemo()); // call run() function t2.start(); // waits thread die t2.join();
from http://docs.oracle.com/javase/tutorial/essential/concurrency/join.html
t.join() causes current thread pause execution until t's thread terminates.
in case paused join method invocation thread main thread.
Comments
Post a Comment