workerthread.java
来自「jConfig,JAVA读取XML的开源项目」· Java 代码 · 共 63 行
JAVA
63 行
/*
* WorkerThread.java
*
* Created on 17. Oktober 2003, 20:05
*/
package org.jconfig.server;
import java.net.Socket;
/**
*
* @author Administrator
*/
public class WorkerThread extends Thread {
private ProtocolHandler handler = null;
private boolean active = false;
private Socket socket = null;
private ServerContext serverContext;
public WorkerThread(ThreadGroup tg,String threadName) {
super(tg,(Runnable)null,threadName);
}
public synchronized void execute(Socket socket,ProtocolHandler handler,ServerContext serverContext) {
if ( this.handler != null ) {
throw new IllegalStateException("Already running");
}
this.socket = socket;
this.handler = handler;
this.serverContext = serverContext;
this.notifyAll();
if ( !active ) {
active = true;
start();
}
}
public void run() {
while (active) {
if (handler != null) {
try {
handler.execute(socket,serverContext);
} catch (Exception e) {
e.printStackTrace();
}
}
this.handler = null;
this.socket = null;
synchronized (this) {
while (active && handler == null) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?