Thread t1 = new myThread();
Thread t2 = new myThread();
Thread t3 = new myThread();
Thread t4 = new myThread();
Thread t5 = new myThread();
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
ArrayList<Thread> mythreads = new ArrayList<Thread>();
int tcount = 1000;
for(int i=0; i< tcount; i++) {
Thread thr = new myThread();
mythreads.add(thr);
thr.start();
}
for (Thread thr : mythreads) {
thr.joint();
}
ExecutorService es = Executors.newCachedThreadPool();
for(int i=0;i<5000;i++)
es.execute(new Runnable() { /* your task */ });
es.shutdown();
boolean finshed = es.awaitTermination(1, TimeUnit.MINUTES);