java transaction clearing processing implementation

There are n (10) threads in a transaction clearing process. Now the following functions need to be implemented. Among the
n (10) threads, n-4 (6) threads are all executed at the same time, and then the remaining 4 threads are executed. .

Use CountDownLatch
CountDownLatch latch=new CountDownLatch(n-4);
After the declaration, plug the latch to n-4 threads, and then let each thread run method at the end, execute latch.countDown(), when n-4 threads When all are executed, the counter of latch is also decremented to 0, and it is completed together at this time. Then assign the latch to new CountDownLatch (4), and start the remaining threads.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326610604&siteId=291194637