// Wait for the child threads to finish job before main thread ends
public Class TestJoin{
public static void main(String args[]) {
Vector
for(int curLen=1; curLen<=5;curLen= curLen+1) //
{
vecThread.add( new Thread(new Inner(curLen)) );
}
for(int i=0;i
vecThread.get(i).start();
}
try {
for(int i=0;i
vecThread.get(i).join();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Class Inner implements Runnable{
int startLen;
public Inner(int start) {
super();
this.startLen = start;
}
private void doJob(){
}
public void run(){
doJob();
}
}
}
Doing the same thread using ThreadPools (It is the standard way)
http://www.journaldev.com/1069/java-thread-pool-example-using-executors-and-threadpoolexecutor
Comments
Post a Comment