3

Suppose I have an Executor executor; somewhere in my application. Is it sufficient to just say setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); as usual and let "the system" deal with it, or do I have to register a listener and call executor.shutdown(); manually before the application exits?

fredoverflow
  • 256,549
  • 94
  • 388
  • 662
  • Did your Executor create the JFrame, or was the Executor created within the JFrame? If the first is true, you'll probably have to call shutdown, otherwise the JVM should handle it... – beatgammit Apr 05 '11 at 19:48
  • 1
    [This](http://stackoverflow.com/questions/1211657/how-to-shut-down-all-executors-when-quitting-an-application) and [this](http://stackoverflow.com/questions/3332832/graceful-shutdown-of-threads-and-executor) might prove useful. – mre Apr 05 '11 at 20:20

2 Answers2

2

If this is a stand-alone application and you don't care that any running threads just exit then you really shouldn't have to worry about it.

If your class is running in a VM that's also running other things (for example a servlet container like Tomcat) you need to explicitly shut down the executor or the threads may continue to run (Tomcat will yell at you and tell you that there's threads it couldn't kill and that you're leaking memory).

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
0

Depending on the application, when you create the Executor you pass it a ThreadFactory that creates daemon threads. These will not prevent application shutdown, but they will also terminate randomly.

Jed Wesley-Smith
  • 4,686
  • 18
  • 20