Authored by qinchao

改成异步

... ... @@ -11,8 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.*;
/**
* Created by chenchao on 2018/10/8.
... ... @@ -22,7 +21,7 @@ public class InBoxFacade {
private final Logger logger = LoggerFactory.getLogger(getClass());
private ExecutorService executorService = Executors.newFixedThreadPool(30);
private ExecutorService executorService = new ThreadPoolExecutor(10, 60, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(30), new InBoxThreadFactory());
@Autowired
private InBoxSDK inBoxSDK;
... ...
package com.yohoufo.order.service.proxy;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 自定义java api线程池内工作线程工厂
* 指定生成线程名称:pool-javaApi-thread-[num]
*/
public class InBoxThreadFactory implements ThreadFactory {
private static final AtomicInteger poolNumber = new AtomicInteger(1);
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
private final ThreadGroup group;
public InBoxThreadFactory() {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = "pool-inboxFacade-processor-" +
poolNumber.getAndIncrement() +
"-thread-";
}
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(group, r,
namePrefix + threadNumber.getAndIncrement(),
0);
if (t.isDaemon())
t.setDaemon(true);
if (t.getPriority() != Thread.NORM_PRIORITY)
t.setPriority(Thread.NORM_PRIORITY);
return t;
}
}
... ...