Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt regarding the ExecutorService shutdown  RSS feed

 
Aniket Harode
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we write the shutdown in the finally statement? and from the below prog. why the shutdown is first exceuted then the thread opertion is worked but it has to work like  the first the thread operation is performed  then the shutdown
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aniket Harode wrote:Why we write the shutdown in the finally statement? and from the below prog. why the shutdown is first exceuted then the thread opertion is worked but it has to work like  the first the thread operation is performed  then the shutdown


Well, it is your code, isn't it? The shutdown() method call is in the finally block because you coded it that way.

As for why the tasks still run, even after shutdown() has been called, it is because it is a graceful shutdown. The tasks in the executor are allowed to complete -- although no new tasks may be added.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!