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 7407715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:46:25+00:00 2026-05-29T05:46:25+00:00

i have a ScheduledExecutorService that gets tasks for periodically execution: scheduler = Executors.newScheduledThreadPool( what

  • 0

i have a ScheduledExecutorService that gets tasks for periodically execution:

scheduler = Executors.newScheduledThreadPool( what size? );

public addTask(ScheduledFuture<?> myTask, delay, interval) {
    myTask = scheduler.scheduleAtFixedRate(new Runnable() {
          // doing work here
     },
          delay,
          interval,
          TimeUnit.MILLISECONDS );
}

The number of tasks the scheduler gets depends solely on the user of my program. Normaly it should be a good idea, afaik, to make the ThreadPoolSize #number_of_Cpu_Threads, so that each CPU or CPU Thread executes one Task at a time, cause this should give the fastest throughput. But what should i do if the Tasks involve I/O (as they do in my program)? The tasks in my program are grabbing data from a server on the internet and saving them in a db. So that means most of the time they are waiting for the data to come in (aka idle). So what would be the best solution for this problem?

  • 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-05-29T05:46:26+00:00Added an answer on May 29, 2026 at 5:46 am

    It really depends on the exact context:

    • How many tasks will be added? (You’ve said it’s up to the user, but do you have any idea? Do you know this before you need to create the pool?)
    • How long does each of them take?
    • Will they be doing any intensive work?
    • If they’re all saving to the same database, is there any concurrency issue there? (Perhaps you want to have several threads fetching from different servers and putting items in a queue, but only one thread actually storing data in the database?)
    • So long as you don’t get “behind”, how important is the performance anyway?

    Ultimately I strongly suspect you’ll need to benchmark this yourself – it’s impossible to give general guidance without more information, and even with specific numbers it would be mostly guesswork. Hard data is much more useful 🙂

    Note that the argument to newScheduledThreadPool only specifies the number of core threads to keep in the thread pool if threads are idle – so it’s going to be doing a certain amount of balancing itself.

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

Sidebar

Related Questions

I have an object that needs to do periodically do some work while the
I am having this problem, I have private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); and task
I have a question regarding the scheduleAtFixedRate() method on ScheduledExecutorService in Java 6. [
I have a poller implemented from Runnable. The poller passes itself into a ScheduledExecutorService.
I have a long-lived server application that is designed to run with minimal downtime
I have a class that looks like the following. This class compiles fine on
i currently have a list of classes every class starts a scheduler like this:
I have a simple Clock Applet that I would like to be able to
Suppose I have a task that is pulling elements from a java.util.concurrent.BlockingQueue and processing
Have a problem that seems easy on paper but i'm having a big problem

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.