Since you are not allowed to modify threads, you will have to suspend pending threads and join () in the thread, which should finish first.
I will leave the following (I replied before an explanation about changing threads was added) for completeness, but with the specified limitations of the problem, these methods will be prohibited:
Ask each of the other threads to call join () on the thread that should finish first. This will make them wait until this thread completes, but using significantly less processor time than the sleep () loop.
Thread first = new FirstThread(); Thread after1 = new AfterThread(first); Thread after2 = new AfterThread(first);
In the launch method for AfterThread:
first.join();
You can also pass a timeout for the connection ().
An alternative method would be to create a lock that only a specific named thread can receive until this named thread receives and releases it once.
source share