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

  • Home
  • SEARCH
  • 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 8818201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:03:18+00:00 2026-06-14T05:03:18+00:00

We are working on an application where a set of objects can be affected

  • 0

We are working on an application where a set of objects can be affected by receiving messages from 3 different sources. Each message (from any of the sources) has a single object as its target. Each message receiver will be running on its own thread.

We want the processing of the messages (after receiving), to be as high-speed as possible, so the message processing against the target objects will be done with another thread from a thread pool. The processing of the message will take longer than the reading/receiving of the messages from the senders.

I am thinking that it will be faster if each thread from the pool is dedicated only to a particular set of objects, for example:

Thread1 -> objects named A-L
Thread2 -> objects named M-Z

with each set of objects (or Thread) having a dedicated queue of messages to pending being processed.

My assumption is that if the only thread synchronization needed is between each receiving thread and one processing thread, for the duration of time that it needs to put the message on a blocking queue, that it will be faster than randomly assigning worker threads to process the messages (in which case there might be 2 different threads with messages for the same object).

My question is really 2 parts:

  1. Do people agree with the assumption that dedicating worker threads
    to a particular set of objects is a better/faster approach?

  2. Assuming this is a better approach, do the existing Java ThreadPool
    classes have a way to support this? Or does it require us coding
    our own ThreadPool implementation?

Thanks for any advice that you can offer.

  • 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-14T05:03:20+00:00Added an answer on June 14, 2026 at 5:03 am

    [Is] dedicating worker threads to a particular set of objects is a better/faster approach?

    I assume the overall goals is to trying to maximize the concurrent processing of these inbound messages. You have receivers from the 3 sources, that need to put the messages in a pool that will be optimally handled. Because messages from any of the 3 sources may deal with the same target object which cannot be processed simultaneously, you want someway to divide up your messages so they can be processed concurrently but only if they are guaranteed to not refer to the same target object.

    I would implement the hashCode() method on your target object (maybe just name.hashCode()) and then use the value to put the objects into an array of BlockingQueues, each with a single thread consuming them. Using an array of Executors.newSingleThreadExecutor() would be fine. Mod the hash value mode by the number of queues and put it in that queue. You will need to pre-define the number of processors to maximum. Depends on how CPU intensive the processing is.

    So something like the following code should work:

     private static final int NUM_PROCESSING_QUEUES = 6;
     ...
     ExecutorService[] pools = new ExecutorService[NUM_PROCESSING_QUEUES];
     for (int i = 0; i < pools.length; i++) {
        pools[i] = Executors.newSingleThreadExecutor();
     }
     ...
     // receiver loop:
     while (true) {
        Message message = receiveMessage();
        int hash = Math.abs(message.hashCode());
        // put each message in the appropriate pool based on its hash
        // this assumes message is runnable
        pools[hash % pools.length].submit(message);
     }
    

    One of the benefits of this mechanism is that you may be able to limit the synchronization about the target objects. You know that the same target object will only be updated by a single thread.

    Do people agree with the assumption that dedicating worker threads to a particular set of objects is a better/faster approach?

    Yes. That seems the right way to get optimal concurrency.

    Assuming this is a better approach, do the existing Java ThreadPool classes have a way to support this? Or does it require us coding our own ThreadPool implementation?

    I don’t know of any thread-pool which accomplishes this. I would not write your own implementation however. Just use them like the code outlines above.

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

Sidebar

Related Questions

I'm working on an internet application that has been set up as a web
I am working on a scientific application that has readily separable parts that can
I am working on Alarm application in which I want to set Large Sound
I'm working on dashboard application where I have to retrieve a set of records
I am working on an MVC2 application and want to set the maxlength attributes
I'm working on a Rails application where I have some a set of two
The application I'm working on requires objects to be created on the fly, some
I am working on a django application that contains a bunch of related objects.
My application loads a data set of approx. 85bm to 100mb each time. The
Yesterday, I succeeded in sending typed objects from a PHP application to a flex

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.