📄 server.java
字号:
/*
* Server.java
*
* Created on 2007年9月14日, 下午12:42
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package semaphore;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
*
* @author Administrator
*/
public class Server {
public static void main(String[] args) throws InterruptedException{
System.out.println("Server is starting.");
//初始化一个初始值为3的CountDownLatch
CountDownLatch latch = new CountDownLatch(3);
//起3个线程分别去启动3个组件
ExecutorService service = Executors.newCachedThreadPool();
service.submit(new ComponentThread(latch, 1));
service.submit(new ComponentThread(latch, 2));
service.submit(new ComponentThread(latch, 3));
service.shutdown();
//进入等待状态
latch.await();
//当所需的三个组件都完成时,Server就可继续了
System.out.println("Server is up!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -