Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:25:59+00:00 2026-06-04T15:25:59+00:00

My code: ScheduledServiceExecutor service = Executors.newSingleThreadScheduledExecutor(); ScheduledFuture future = service.scheduleWithFixedDelay( runnable, 1, 1, TimeUnit.MILLISECONDS

  • 0

My code:

ScheduledServiceExecutor service = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture future = service.scheduleWithFixedDelay(
  runnable, 1, 1, TimeUnit.MILLISECONDS
);
// ...
// now it's time to shut it all down
future.cancel(true);
service.shutdown();

Am I right here? Maybe I should do:

service.shutdown();
future.cancel(true);

What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:26:01+00:00Added an answer on June 4, 2026 at 3:26 pm

    In this case, you only need the call to shutdown().

    There are two options in the ScheduledThreadPoolExecutor, which is what is being created behind the scenes here. getExecuteExistingDelayedTasksAfterShutdownPolicy() defaults to true and getContinueExecutingPeriodicTasksAfterShutdownPolicy() defaults to false. So, simply shutting down the service will cause periodic tasks to be canceled, but any delayed tasks will still be executed. Since the task in question is a periodic task, it will be canceled upon shutdown.

    My personal opinion is that it’s better to call the .cancel(true) manually before shutdown. While operationally this has no different effect, I think it’s good for programmers who may not know the options on the executor to see that the periodic task is meant to be canceled upon shutdown. This also means that if anyone ever comes in and changes the executor to one which doesn’t cancel upon shutdown, this task will still be canceled. So really, I think the main benefit here is clarity of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code can be perfect, and also perfectly useless at the same time. Getting requirements
Code for webpage such that if anyone closes it, then next time when he
code id date time difference AiK4JJ kcy2000ok 2012-01-31 17:25:41 13 unBG1D gktoql 2012-01-31 17:25:35
Code says it all: teststring = helloworld$ string_from_user = world$ regexp = Regexp.escape(string_from_user) #
code: <a href=...><img src=..' /><span>..</span></a> works fine in all cases, but <a href=...> <img
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which
Code for server: http://stikked.com/view/64826511 Network Code for client: http://stikked.com/view/38974838 Basically, the client connects to
Code in the book Beginning iPhone Development (by Dave Mark & Jeff LaMarche) assigns
//CODE $entries = $model->fetchEntries(); $feedUri = '/rss/'; //link from which feed is available $link
Code is as follows but I get a ytplayer is not defined error. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.