- Move common "ExecutionException" handling-code into its own method: "GenericUtils.getSelectedStackTraceForCausedException()".
- Avoid a double log.
- Code polishing.
@ -112,22 +112,16 @@ public class ScheduledTasks {
if(!future.get())// Get and see if an exception is thrown. This blocks the current thread, until the task of the future has finished.
numFailedTasks++;
}catch(ExecutionExceptionee){// These can be serious errors like an "out of memory exception" (Java HEAP).
// The stacktrace of the "ExecutionException" is the one of the current code and not the code which ran inside the background-task. Try to get the cause.
Throwablethrowable=ee.getCause();
if(throwable==null){
logger.warn("No cause was retrieved for the \"ExecutionException\"!");
@ -164,18 +164,14 @@ public class BulkImportServiceImpl implements BulkImportService {
// In case all the files failed to be bulk-imported, then we will detect it in the "numSuccessfulSegments"-check later.
// The failed-to-be-imported files, will not be deleted, even if the user specifies that he wants to delete the directory.
}catch(ExecutionExceptionee){// These can be serious errors like an "out of memory exception" (Java HEAP).
// The stacktrace of the "ExecutionException" is the one of the current code and not the code which ran inside the background-task. Try to get the cause.
Throwablethrowable=ee.getCause();
if(throwable==null){
logger.warn("No cause was retrieved for the \"ExecutionException\"!");
// The stacktrace of the "ExecutionException" is the one of the current code and not the code which ran inside the background-task. Try to get the cause.
ThrowablecausedThrowable=thr.getCause();
if(causedThrowable==null){
logger.warn("No cause was retrieved for the \"ExecutionException\"!");
// The stacktrace of the "ExecutionException" is the one of the current code and not the code which ran inside the background-task. Try to get the cause.
throwable=e.getCause();
if(throwable==null){
logger.warn("No cause was retrieved for the \"ExecutionException\"!");
throwable=e;
}
}
logger.error("",throwable);
// We do not know if the failed "future" refers to a "payload" or to a "attempt".
// So we cannot increase a specific counter. That's ok, the only drawback if that we may try to "load" the non-existent data and get an exception.
}catch(ExecutionExceptionee){// These can be serious errors like an "out of memory exception" (Java HEAP).