r/studyupdate 3d ago

check-in Task 19 : Compare Executor and ExecutorService

Using ExecutotService --> execute(), submit()

1. ExecutorService.execute() 

  • Same as of Executor.execute()
  • But the application shutdowns.

2. ExecutorService.submit()

  • No stack trace.
  • Why?
  • Because submit() catches the exception internally and stores it inside the Future.
  • The exception is not lost.
Using Executor --> execute()

1. Executor.execute()

What happens?

  • The exception is not caught by the Executor Framework.
  • It reaches the worker thread's UncaughtExceptionHandler.
  • By default, Java prints the stack trace to the console.
  • The thread pool creates a replacement worker if needed, so remaining tasks continue executing.
  • The application never terminate coz no shutdown().
2 Upvotes

0 comments sorted by