serverthread.java
来自「用NETBEANS做的一个关于Java的小小的demo.大家赐教」· Java 代码 · 共 78 行
JAVA
78 行
/*
* ServerThread.java
*
* Created on 2007年9月13日, 下午10:30
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package OldThread;
/**
*
* @author Administrator
*/
public class ServerThread {
Object concLock = new Object();
int count = 2;
public void runTwoThreads() {
//启动两个线程去初始化组件
new Thread(new ComponentThread1(this)).start();
new Thread(new ComponentThread1(this)).start();
// Wait for other thread
while(count != 0) {
System.out.println("count = " + count);
synchronized(concLock) {
try {
concLock.wait();
System.out.println("Wake up.");
} catch (InterruptedException ie) { //处理异常
}
}
System.out.println("Server is up.");
}
}
public void callBack() {
synchronized(concLock) {
count--;
concLock.notifyAll();
}
}
public static void main(String[] args){
ServerThread server = new ServerThread();
server.runTwoThreads();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?