Control thread execution order (java)

Here the idea is just to say, there is no specific code.

List three scenarios

  1. Use join, from the source point of view, join method is in fact calling Object.wait (), so that the main thread waits for executing the specified thread to continue execution, personally feel is not good, have blocked the main thread, multi-thread and have lost the meaning of a half.

2. Create only one thread of a thread pool, then in order to perform a few tasks, which is certainly in order.

3. Suppose there are three threads requires very complex calculation, calculation needs requires three concurrent threads, but the end of the calculation results to be output together with confluence. This lock can be used when LatchDownCount, initializes a value of a latch 3, each thread has finished the calculation of a value of -1, then the final value before the output latch.await (), calculating the three threads are finished, they will not await ( ), perform the final step.

Published 21 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/a5552157/article/details/105176331