packagejoin;importjava.util.ArrayList;importjava.util.Random;publicclassMain{publicstaticvoidmain(Stringarg[])throwsException{Randomr=newRandom();ArrayList<Thread>threads=newArrayList<Thread>();//create some threadsfor(inti=0;i<10;i++){MyThreadmt=newMyThread(r);threads.add(mt);}System.out.println("All threads have been created.");//start all the threadsfor(Threadt:threads){t.start();}System.out.println("All threads have been started.");System.out.println("Start waiting for all thread to finish...");//wait all the thread to finishfor(Threadt:threads){t.join();}System.out.println("...All thread finished!");}}