Java thread: The obstacle class is added to the new feature-obstacle Java 5. To meet a new design requirement, such as a large task, it is often necessary to assign many sub-tasks to execute. Only when all sub-tasks are completed can the sub-tasks be executed. At this time, you can select the barrier. Barrier is a method of multi-thread concurrency control, which is easy to use. The following is an example: import java. util. concurrent. brokenBarrierException; import java. util. concurrent. cyclicBarrier;/*** Java thread: new feature-barrier ** @ author leizhimin 10:50:10 */public class Test {public static void main (String [] args) {// create the barrier and set MainTask to the Runnable task when all the specified number of threads reach the barrier point. Required icbarrier cb = new CyclicBarrier (7, new MainTask (); new SubTask ("A", cb ). start (); new SubTask ("B", cb ). start (); New SubTask ("C", cb ). start (); new SubTask ("D", cb ). start (); new SubTask ("E", cb ). start (); new SubTask ("F", cb ). start (); new SubTask ("G", cb ). start () ;}/ *** */class MainTask implements Runnable {public void run () {System. out. println (">>>> The Chief Executive Officer is executed! <") ;}}/*** SubTask */class SubTask extends Thread {private String name; private javasicbarrier cb; SubTask (String name, CyclicBarrier cb) {this. name = name; this. cb = cb;} public void run () {System. out. println ("[subtask" + name + "] started to run! "); For (int I = 0; I <999999; I ++); // simulate time-consuming task System. out. println ("[subtask" + name + "] has been executed, and the barrier has been notified! "); Try {// The Notification barrier has completed cb. await ();} catch (InterruptedException e) {e. printStackTrace ();} catch (BrokenBarrierException e) {e. printStackTrace () ;}} running result: [subtask E] execution started! [Subtask E] The execution is completed, and the barrier has been notified! [Subtask F] execution started! [Subtask G] execution started! [Subtask F] The execution is completed, and the barrier has been notified! [Subtask G] The execution is completed, and the barrier has been notified! [Subtask C] execution started! [Subtask B] execution started! [Subtask C] The execution is completed, and the barrier has been notified! [Subtask D] execution started! [Subtask A] execution started! [Subtask D] The execution is completed, and the barrier has been notified! [Subtask B] The execution is completed, and the barrier has been notified! [Subtask A] The execution is completed, and the barrier has been notified! >>>> The Chief Executive Officer is ready! <Process finished with exit code 0: The execution result shows that when all sub-tasks are completed, the Director executes the tasks and achieves the control goal.