Configuration d'un pool async
Fri Jul 21 2023 17:21:02 GMT+0000 (Coordinated Universal Time)
Saved by
@ambre
@Configuration
@EnableAsync
@Slf4j
public class AsyncConfiguration implements AsyncConfigurer {
@Value("${thread.pool.size}")
private int poolSize;
@Override
public Executor getAsyncExecutor() {
return Executors.newFixedThreadPool(poolSize);
}
//Si on veut une gestion particulière pour les exceptions
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return ((ex, method, obj) -> {
String errorMessage = "Async exception message " + ex.getMessage() + " method " + method.getName() + " " + Arrays.toString(obj);
log.error(errorMessage, ex);
specialTreatmentForAsynchExport(ex, method, errorMessage, obj);
});
}
}
content_copyCOPY
Puis devant la méthode qu'on veut gérer en async:
@Async
public void treatFile(File file) {
Comments