Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

isShutdown - does it return true as soon as the shutdown() method is called?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this statement in a free mock test. Is this correct about the ExecutorService?
"The isShutdown() method returns true once the shutdown() method is called"

As per the API, the isShutdown() method only returns true if this executor has been shut down.

Please do confirm.
 
Marshal
Posts: 26519
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So your question is equivalent to

You, sort of wrote:Do "The shutdown() method has been called" and "The executor has been shut down" mean the same thing?



And since the API says "Initiates an orderly shutdown...", that would suggest that "shutdown" is a process which is started by the shutdown() method, which doesn't wait for that process to complete.

On the other hand, there's a method isTerminated() for which the API says "Returns true if all tasks have completed following shut down." Also on that other hand, the isShutdown() method "Returns true if this executor has been shut down."

One would assume that those two methods are not meant to have exactly the same purpose. So that assumption would imply that "has been shut down" is not the same as "all tasks have completed following shut down".

Notice also that the API, in the preamble, says "An ExecutorService can be shut down, which will cause it to reject new tasks."

Summary: To me that means that the shutdown() method causes the service to be "shut down", so that it won't accept any more tasks. Then it proceeds to wait for the tasks that it's all running to complete, after which it's considered "terminated". So in my opinion the answer to your question is "Yes". (Note the word "opinion".)

However the API is scandalously vague about what "shutdown" means. Sometimes it's an event which prevents new tasks from being accepted, and sometimes it's a process which waits for existing tasks to complete. So I don't think that would be a suitable question for a certification exam.
 
Beware the other head of science - it bites! Nibble on this message:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic