Skip to content

Instantly share code, notes, and snippets.

@aozturk
Last active September 22, 2017 05:57
Show Gist options
  • Save aozturk/8e34ffd4096a38ea06b2 to your computer and use it in GitHub Desktop.
Save aozturk/8e34ffd4096a38ea06b2 to your computer and use it in GitHub Desktop.
final class MyTask implements Runnable {
@Override
public void run() {
try {
System.out.println("My task is started running...");
// ...
anotherMethod();
// ...
} catch (Throwable t) {
System.err.println("Uncaught exception is detected! " + t
+ " st: " + Arrays.toString(t.getStackTrace()));
// ... Handle the exception
}
}
private void anotherMethod() {
throw new ArithmeticException();
}
}
public class ProactiveHandler {
public static void main(String[] args) {
// Create a fixed thread pool executor
ExecutorService threadPool = Executors.newFixedThreadPool(10);
threadPool.execute(new MyTask());
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment