java - Design pattern for returning responses from child threads -


i looking design pattern parent thread spawn multiple child threads. each child thread perform computation , return appropriate result.

the parent thread waiting child threads complete. after child threads completed, consolidated result sent parent thread.

the parent thread proceed consolidated result.

check join method of thread class. here working sample:

import java.lang.*;  public class threads {   public void callchildren() throws exception {     thread t = new thread(new childthread());    t.start();    t.join();    system.out.print(t.getname());    system.out.println(", status = " + t.isalive());   }     public static void main(string[] args) throws exception{          for(int = 0 ; < 4; ++) {             new threads().callchildren();          }           system.out.println("printing parent thread after child thread complete.");    }     private class childthread implements runnable{      @override     public void run() {         system.out.println("thread started:::"+thread.currentthread().getname());         try {             thread.sleep(1000);         } catch (interruptedexception e) {             e.printstacktrace();         }         system.out.println("thread ended:::"+thread.currentthread().getname());     }    }  }  

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -