Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how does shutdown method work in ExecutorService

Posted on 2013-05-16
1
346 Views
Last Modified: 2013-05-16
Hi, my questions is about how the shutdown method works in ExecutorService.
I can see from the api that:
shutdown()
          Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

In the implementation i see it calls the shutdown method which disables new tasks from being submitted, then it calls shutdownNow()which cancels currently executing tasks.

My question is, what exactly happens to threads that are in execution when that happens? what if i have a thread responsible for placing a order to buy or sell or a thread responsible for delivering something to a router, what will happen to it if the shutdown method is called in this case?

Thanks
0
Comment
Question by:Squadless
1 Comment
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39171676
if you call only "shutdown()" then current tasks will be finished and then ExecutorService will exit.
see this, it will give you more information how to shutdown ExecutorService gracefully:
http://thelifeofajavadeveloper.blogspot.com/2012/03/how-to-shutdown-executorservice.html
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 38
how to add new optional parameter to JSP 1 49
login form jsp example 2 35
java imports not found 4 20
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question