错误如下:Error creating bean with name 'transactionManager': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
解决方式如下
//线程池定义
private static final int CPU_CNT = Runtime.getRuntime().availableProcessors();
private static final int THREAT_CNT = CPU_CNT;
private ExceutorService fixedThreadPool = Executors.newFixedThreadPool(THREAT_CNT );
public void testCommisionCalu() throws InterruptedException {
Thread mainThread = Thread.currentThread();
List<Object> orders = Lists.newArrayList();
OrderDTO orderDTO = new OrderDTO ();
orderDTO .setApplyOrderId("100000000001");
orderDTO .setOrderStatus("gc129");
orderDTO .setHanlderId(100L);
orders.add(orderDTO );
//更新订单状态&&计算佣金 //需要把异步调用给注释掉,测试环境中会报:Error creating bean with name 'transactionManager':
// Singleton bean creation not allowed while the singletons of this factory are in destruction
// (Do not request a bean from a BeanFactory in a destroy method implementation!)
fixedThreadPool.execute(new Runnable() {
public void run() {
try {
orderService.sysOrderStatusPostProcessor(orders);
} catch (Exception e) {
//中断休眠的主线程
mainThread.interrupt();
log.error("getClueOrders->sysOrderStatusPostProcessor Exception:",e);
}
}
});
//主线程休眠目的是:让线程池的中线程可以继续创建:transactionManager ,因为factory 没有被销毁
Thread.sleep(100000000);
}
来源:oschina
链接:https://my.oschina.net/qimhkaiyuan/blog/4292878