How to control the sequential execution threads

There are two approaches to this:

 

1, sequential method of execution by join assurance thread

join the main thread is waiting for the child after the end of the thread to continue execution.

The source code is called join () -> wait () method, so that the main thread waits for the child thread.

 

2, the thread pool by: newSingleThreadExecutor ();

The main use is

static ExecutorService executorService =Executors.newSingleThreadExecutor()

public static void main(***){
    

  executorService.submit(Thread1)
  
executorService.submit(Thread2)
   executorService.submit(Thread3) 

}

  

Guess you like

Origin www.cnblogs.com/daohangtaiqian/p/12335336.html