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!!

  1. implement runnable

    public class threaddemo implements runnable {          public void run() {           //do need        } }
  2. 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

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -