Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
QianLongGit committed Apr 4, 2016
1 parent 3c4139f commit cff1c8f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) {
log.info("监听处理处理web容器关闭事件");

log.info("关闭线程池");
ExecutorFactory.getExecutor().shutdown();
ExecutorFactory.EXECUTE.getExecutor().shutdown();

}
}
21 changes: 16 additions & 5 deletions src/main/java/com/imageServer/factory/ExecutorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,31 @@

/**
* 并发线程执行对象工厂方法
* 单例
* Copyright 2014-2015 the original ql
* Created by QianLong on 15-1-23.
*/
public class ExecutorFactory {
public enum ExecutorFactory {

private static ExecutorService executorService = null;
EXECUTE;

private ExecutorService executorService;

ExecutorFactory(){
if(executorService == null){
final int cpuCore = Runtime.getRuntime().availableProcessors();
//线程数(当前CPU数+1)
final int poolSize = cpuCore+1;
//定义并发执行服务
executorService = Executors.newFixedThreadPool(poolSize);

}
}
/**
* 获取执行类
* @return
*/
public static ExecutorService getExecutor(){
public ExecutorService getExecutor(){
if(executorService == null){
final int cpuCore = Runtime.getRuntime().availableProcessors();
//线程数(当前CPU数+1)
Expand All @@ -31,6 +44,4 @@ public static ExecutorService getExecutor(){
return executorService;
}

private ExecutorFactory(){}

}
2 changes: 1 addition & 1 deletion src/main/java/com/imageServer/util/ExecuteThreadUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class ExecuteThreadUtil {

private static ExecutorService executorService = ExecutorFactory.getExecutor();
private static ExecutorService executorService = ExecutorFactory.EXECUTE.getExecutor();

/**
* 执行一个无返回值的线程任务
Expand Down

0 comments on commit cff1c8f

Please sign in to comment.