You have thread T1, T2 and T3, how will you ensure that thread T2 run after T1 and thread T3 run after T2?
Solution 1:
try
{
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
t3.join();
} catch (InterruptedException e) {
e.printStackTrace();
}Solution 2:
ExecutorService excutoService = Executors.newSingleThreadExecutor();
excutoService.submit(t1);
excutoService.submit(t2);
excutoService.submit(t3);
No comments:
Post a Comment