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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:02:00+00:00 2026-06-05T04:02:00+00:00

we are currently trying to tweak performance by using multithreading in our java app.

  • 0

we are currently trying to tweak performance by using multithreading in our java app.
We have a long running serial task which we would like to split to multi CPU cores.

Basically we have list with let’s say 100.000 items / things to do.

My question now is is it better to do:

Option 1 (Pseudocode):

for(i = 0; i < 100000; i++){
  threadpool.submit(new MyCallable("1 thing to do"))
}

This would add 100000 runnables/callables to the queue of the threadpool (current LinkedBlockingQueue)

or is it better to do:
Option 2 (Pseudocode)

for(i = 0; i < 4; i++){
  threadpool.submit(new MyCallable("25000 things to do"))
}

We have tried already option 1, and we didn’t notice any performance improvement, although we can clearly see that multiple threads are working like crazy and also 4 CPU cores used. But my feeling is that there is some overhead in option 1 because of the many tasks. We haven’t tried option 2 yet, but my feeling is, that it could speed up things as there is less overhead. We are basically splitting the list into 4 larger chunks instead 100000 single items.

Any thoughts on this?

Thanks

  • 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-05T04:02:03+00:00Added an answer on June 5, 2026 at 4:02 am

    What matters is that you minimize the amount of context switching, and maximize the amount of work per task that it spends computing. As a practical matter, if your tasks are computing, exceeding the number of physical CPUs isn’t going to help. If your tasks actually do a lot of I/O and I/O waits, you want to have many of them so there is always a bunch of “ready” tasks available when one blocks.

    If you really have 25000 things to do, and the things are computation, I’d probably set up 32 threads (more CPUs than you have, but not a lot of extra overhead) and parcel out 10-50 units of work to each one if those units are relatively small.

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

Sidebar

Related Questions

I'm currently trying to optimize my website, which is run on the Google App
im currently trying to make a simple IRC Gui Client. Im using the SmartIrc4net
I currently have another question to do with path finding in Java. However I
I'm using Python 2.7 libtcod to make a Roguelike, and currently trying to get
I'm currently trying to create a class which implements IEnumerable<T> in order to construct
Currently trying to create an XML system using Ogre and the STL. As a
I have a web app that needs both functionality and performance tested, and part
Im currently trying to bind the DataGrid.ItemsSource to a custom RowCollection, which implements IList
I currently trying to setup otp logging in my app as documentation recommends to
Currently trying to insert an object into the Customer table using a test SQL

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.