@@ -0,0 +1,2005 @@
+package org.onetwo.common.spring.task;%0A%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.ThreadFactory;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0Aimport org.onetwo.common.log.JFishLoggerFactory;%0Aimport org.slf4j.Logger;%0Aimport org.springframework.beans.factory.DisposableBean;%0Aimport org.springframework.beans.factory.InitializingBean;%0Aimport org.springframework.util.Assert;%0A%0A/**%0A * @author weishao zeng%0A * %3Cbr/%3E%0A */%0A%0Aabstract public class BaseExccutorService implements InitializingBean, DisposableBean %7B%0A%09protected final Logger logger = JFishLoggerFactory.getLogger(getClass());%0A%0A%09final private String threadName;%0A%09private ExecutorService executor;%0A%09private int threadNumber = 1;%0A%09private AtomicBoolean stop = new AtomicBoolean(false);%0A%0A%09public BaseExccutorService(String threadName) %7B%0A%09%09Assert.hasText(threadName, %22threadName must has text%22);%0A%09%09this.threadName = threadName;%0A%09%7D%0A%0A%0A%09@Override%0A%09public void afterPropertiesSet() throws Exception %7B%0A        executor = Executors.newFixedThreadPool(threadNumber, new ThreadFactory() %7B%0A    %09%09@Override%0A    %09%09public Thread newThread(Runnable r) %7B%0A    %09%09%09return new Thread(r, threadName);%0A    %09%09%7D%0A    %09%7D);%0A        start();%0A%09%7D%0A%0A%09%0A%09public void stop() %7B%0A%09%09this.stop.set(true);%0A%09%7D%0A%09%0A%09public boolean isStop() %7B%0A%09%09return this.stop.get();%0A%09%7D%0A%09%0A%09public void start() %7B%0A        this.executor.execute(() -%3E %7B%0A        %09doTask();%0A        %7D);%0A%09%7D%0A%0A%09abstract protected void doTask();%0A%0A//%09protected void doTask() %7B%0A//%09%09try %7B%0A//%09%09%09while(true) %7B%0A%09%09%09%09// do something%0A//%09%09%09%7D%0A//%09%09%7D catch (Throwable e) %7B%0A//%09%09%09logger.error(%22%E8%AE%B0%E5%BD%95%E9%94%99%E8%AF%AF%22, e);%0A//%09%09%7D%0A//%09%09// %E8%8B%A5%E9%9D%9E%E5%81%9C%E6%AD%A2%E7%8A%B6%E6%80%81%EF%BC%8C%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B...%0A//%09%09if (!isStop()) %7B%0A//%09%09%09logger.info(%22%E9%9D%9E%E6%AD%A3%E5%B8%B8%E5%85%B3%E9%97%AD%EF%BC%8C%E5%B0%9D%E8%AF%95%E9%87%8D%E6%96%B0%E2%80%A6%E2%80%A6%22);%0A//%09%09%09this.doTask();%0A//%09%09%7D%0A//%09%7D%0A%09%0A%09public void shutdownExecutor() %7B%0A%09%09if (executor!=null) %7B%0A%09%09%09executor.shutdown();%0A%09%09%09executor = null;%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void destroy() throws Exception %7B%0A%09%09this.shutdownExecutor();%0A%09%7D%0A%0A    protected void finalize() %7B%0A%09%09this.shutdownExecutor();%0A    %7D%0A%7D%0A

add base excecutor