import java.util.List;
import java.util.Map;
import java.util.Queue;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
public class RetrieveStatisProxy {
static Logger logger = Logger.getLogger(RetrieveStatisProxy.class);
static Thread doWorkThread = null;
static boolean isRunThread = false;
static Queue<RetrieveResultStatis> QUEUE = null;
static Long TIME_UNIT = 1000l;
static final Object SyncRoot = new Object();
static FaceSystemConfig config = BeanHelper.getBean(FaceSystemConfig.class);
public static void start(){
startThread();
}
static void startThread(){
if(null == doWorkThread){
if(!isRunThread){
isRunThread = true;
doWorkThread = new Thread(doWork);
doWorkThread.setName(RetrieveStatisProxy.class.getSimpleName());
doWorkThread.start();
}
}
}
public static void add(RetrieveResultStatis statis){
synchronized (SyncRoot) {
if(null == QUEUE){
QUEUE = new LinkedList<>();
}
QUEUE.offer(statis);
}
}
static Runnable doWork = new Runnable() {
@Override
public void run() {
logger.debug("--------RetrieveStatisProxy start to work!!!-------");
while(isRunThread){
try{
while(null != QUEUE && QUEUE.size()>0){
RetrieveResultStatis statis = QUEUE.poll();
logger.debug(String.format("------poll from queue:[%s]-----",statis.toString()));
handle(statis);
}
}catch(Exception e){
logger.error(e.getMessage(),e);
}
ThreadHelper.sleepThread(TIME_UNIT*5);
}
}
};
}