When using the ExecutorService returned by Executors.newSingleThreadExecutor(), how do I interrupt it?
When using the ExecutorService returned by Executors.newSingleThreadExecutor() , how do I interrupt it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order to do this, you need to
submit()a task to anExecutorService, rather than callingexecute(). When you do this, aFutureis returned that can be used to manipulate the scheduled task. In particular, you can callcancel(true)on the associatedFutureto interrupt a task that is currently executing (or skip execution altogether if the task hasn’t started running yet).By the way, the object returned by
Executors.newSingleThreadExecutor()is actually anExecutorService.