以下是我写的代码,但是executorServices.execute()方法不执行,这是为啥呀
List<String> pricePos = preferProductPriceMapper.selectInfobyCustNumber(queryMap);
try {
for (int i = 0; i < pricePos.size(); i++) {
final String number = pricePos.get(i);
executorServices.execute(() -> {
System.out.println(Thread.currentThread().getName() + "-结果:" + number);
PreferProductPricePo preferProductPricePo = new PreferProductPricePo();
preferProductPricePo.setCustNumber(number);
List<PrefetProductPriceSenderInfoPo> prefetProductPriceSenderInfos = preferProductPriceMapper.selectInfobyCustNumberList(preferProductPricePo);
for (PrefetProductPriceSenderInfoPo productPriceSenderInfoPo : prefetProductPriceSenderInfos) {
System.out.println(Thread.currentThread().getName() + "-结果:" + number);
String custNumber = productPriceSenderInfoPo.getCustNumber();
String id = productPriceSenderInfoPo.getId().toString();
cmcDiscountProducer.send(custNumber + id, JSONObject.toJSONString(productPriceSenderInfoPo));
}
});
}
} finally {
executorServices.shutdown();
}
遇到了一样的情况
// ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 5,
// 5, TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>());
// String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
// .format(new Date(System.currentTimeMillis()));
// tpe.execute(
// ()-> System.out.println(format)
// );
代码看着没问题,是不是查询到的
– 。淑女范erり 3年前pricePos
没有数据啊