Ich bin neu zu Frühling mit ExecutorService
. Bitte können Sie den folgenden Code bestätigen? Ich habe ExecutorSerive
in Methode initiert und es in der @PreDestroy
Methode destoryed.Ist es notwendig, shutdownNow()
zu benennen. Wenn ja, wo wäre es?Spring mit Executor Service
private static final int FIXED_THREAD_POOL_SIZE =3;
private static final Log LOGGER = LogFactory.getLog(HotelProgramInfoHistoryService.class);
private ExecutorService executorService;
@PostConstruct
public void initialize() throws Exception {
if(executorService == null) {
this.executorService = Executors.newFixedThreadPool(FIXED_THREAD_POOL_SIZE);
}
}
public void sendRequest(DomainSecurity security, HotelProgramInfo hotelProgramInfo) {
try {
ProgramInfoHistoryUpdateTask programInfoHistoryUpdateTask = new ProgramInfoHistoryUpdateTask(hotelProgramInfo);
this.executorService.submit(programInfoHistoryUpdateTask);
} catch (Exception exception) {
LOGGER.error("Exception occurred while submitting update task ", exception);
}
}
@PreDestroy
public void cleanUp() throws Exception {
if(executorService != null)
{
executorService.shutdown();
}
}
}