📄 server.java
字号:
//==============================================================
// Server.java - Server class queues and processes jobs using threads
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com 中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com
// 电子邮件: Java@ChinaITLab.com
//==============================================================
import Queue;
import Job;
class Server implements Runnable {
Queue q = new Queue(); // Construct our Queue object
public void run() {
try {
doWhenReady(); // Do the server's activities
} catch (InterruptedException e) {
return;
}
}
// Perform server activities until shutdown
private synchronized void doWhenReady()
throws InterruptedException {
for (;;) { // Do "forever" loop
while (q.isEmpty()) // Wait until there is a job in
wait(); // the queue
Job j = (Job)q.get(); // Get the job
j.doJob(); // Do the job
} // for
}
// Add a new job to the server's queue
// This returns immediately; the job is not performed
// until the server thread detects the queue is no longer
// empty.
public synchronized void add(Job j) {
q.add(j);
notifyAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -