Skip to content

Commit

Permalink
handle thread exceptions - make program exit
Browse files Browse the repository at this point in the history
  • Loading branch information
dror27 committed Aug 15, 2024
1 parent b4a8884 commit 2f77208
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,20 @@ public void run() {
}
}
});
writerWorker.setUncaughtExceptionHandler(getUncaughtExceptionHandler());
writerWorker.start();;
}

// if using threads, set handler for this thread as well
if ( threadedWalker || threadedWriter ) {
Thread.currentThread().setUncaughtExceptionHandler(getUncaughtExceptionHandler());
}

// if using threaded walker extend reference cache to avoid thrushing
if ( threadedWalker ) {
CachingIndexedFastaSequenceFile.requestedCacheSize = CachingIndexedFastaSequenceFile.DEFAULT_CACHE_SIZE * CACHE_SIZE_FACTOR;
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void onTraversalStart() {
if ( threadedWalker ) {
applyQueue = new LinkedBlockingQueue<>(CAPACITY);
worker = new Thread(this);
worker.setUncaughtExceptionHandler(getUncaughtExceptionHandler());
worker.start();
}
}
Expand Down Expand Up @@ -103,4 +104,13 @@ public void run() {

public abstract boolean acceptRead(GATKRead read, ReferenceContext referenceContext, FeatureContext featureContext);
public abstract void applyPossiblyThreaded(final GATKRead read, final ReferenceContext referenceContext, final FeatureContext featureContext);

public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() {
Thread.UncaughtExceptionHandler handler = (th, ex) -> {
System.out.println("Uncaught exception: " + ex);
ex.printStackTrace(System.out);
System.exit(-1);
};
return handler;
}
}

0 comments on commit 2f77208

Please sign in to comment.