67,512
社区成员
发帖
与我相关
我的任务
分享
public class StatDataWorker {
private final PoolWorker thread;
private final LinkedList queue = new LinkedList();
public StatDataWorker() {
thread = new PoolWorker();
}
public void execute(ParsedData parsedData) {
synchronized(this.queue) {
this.queue.add(parsedData);
this.queue.notify();
}
}
private class PoolWorker extends Thread {
private ParsedData parsedData = null;
public void run() {
while (true) {
synchronized(queue) {
while (queue.isEmpty()) {
try {
queue.wait();
} catch (Exception ex) {ex.printStackTrace();}
}
try {
this.parsedData = (ParsedData) queue.removeFirst();
} catch (Exception ex) {ex.printStackTrace();}
}
try {
if(this.parsedData != null) {
StatDataParser _parser = new StatDataParser();
_parser.parse(this.parsedData);
_parser.save();
this.parsedData = null;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
}