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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:36:08+00:00 2026-06-14T21:36:08+00:00

In the common workQueue , theadPoolExecution architecture , when a job arrives , only

  • 0

In the common workQueue , theadPoolExecution architecture , when a job arrives , only one thread is invoked and that thread completes the work.
Instead i want all threads to be invoked and all the threads to perform the task.

My scenario is as below.
I have 5000 data items and i have to run a task on each data item. Running it one by one has proved slow , hence i want to use threading here.
Here lets say i employed 5 threads. The first thread will execute the first 1000 data items , the second will execute the next 1000 and other will follow.
Now when a job arrives which needs to be executed on this 5000 data items , all the 5 threads have to be invoked or rather put back from sleep , so that it can perform its task.

How is this possible using theadPoolExecution in java.
I am aware that inserting 5 copy of the same job to the queue might help.
But this has many side effects like if a thread quickly completes its job , it will take up someone else work.

Thanks
Vineeth

  • 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-14T21:36:09+00:00Added an answer on June 14, 2026 at 9:36 pm

    Since you want first thread to process first 1000 items and the second thread process another 1000 items, this mean you want threads to execute different tasks. If, in contrast, all threads execute same task, this mean all threads execute the same data items (which is of no use and may cause problems when threads will save results into the same place).

    So please, don’t do “inserting 5 copy of the same job”. Submit different tasks, with different data ranges.

        for (int k=0; k<N; k+=1000) {
           final int datapoint=k;
           executor.execute(new Runnable() {
               processDataRange(datapoint, datapoint+1000);
           });
        }
    

    Here in each pass of the loop, new task with different parameters is created and submitted to the executor.

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

Sidebar

Related Questions

A common annoyance in Matlab is that, if one forgets the semicolon, one might
One common case being the app has users and groups, only a user who
Common scenario: I have a library that uses other libraries. For example, a math
A common problem is that for validation you need to run the same code
A common question that comes up from time to time in the world of
Common Lisp HyperSpec says that require and ****modules**** are deprecated. But I still see
A common problem that I have with web pages is floating div tags creeping
The common solution to turn multiple white spaces into one white space is by
A common pattern in C++ is to create a class that wraps a lock
The common sense tells that the Doxygen comment blocks have to be put in

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.