因为 boar application 会维持一个 boarManager ,而 一个boar 会有一个 AbstractBoarHandler ,故而这里
代码这样写会是很消耗资源地 ,你平时写代码有注意这些没 ...
/**
* Copyright (C) 2006 the original author or authors.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package com.boar;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.boar.domain.Instruct;
import com.boar.domain.InstructManager;
import com.boar.domain.impl.DBInstructManager;
/**
* Abstract Handler
*
* @author <a href="zhuaming@gmail.com">Ben </a>
*
*/
public abstract class AbstractBoarHandler {
protected InstructManager instructManager = new DBInstructManager();
protected List<Instruct> instructs = null;
private String workgroupID ;
public AbstractBoarHandler(String workgroupID) {
this.workgroupID = workgroupID;
instructs = instructManager.getInstructs(workgroupID);
ScheduledExecutorService scheduledExecute = Executors.newSingleThreadScheduledExecutor();
scheduledExecute.scheduleAtFixedRate(new Worker(),1, 120, TimeUnit.SECONDS);
}
public abstract String process(String packet);
private class Worker implements Runnable {
public void run() {
instructs = instructManager.getInstructs(workgroupID);
}
}
}