Results 1 to 6 of 6

Thread: Thread Pooling

  1. #1
    jshailes is offline Member
    Join Date
    Jan 2009
    Posts
    7
    Rep Power
    0

    Default Thread Pooling

    I'm trying to set up thread pooling so that I can have many threads consuming and processing messages from a JMS queue. I thought I had found the solution upon reading about ThreadPoolTaskExecutor however I can't seem to find a way of prioritising thread execution. If I can briefly explain an abstraction of what I'm trying to do:

    1. The jms queue is being populated from an external source with messages of the format {customerId, foodId}, for example customer 1 has bought an apple. Customer 1 may also have bought a pear but this would be a separate message.

    2. Only one thread in the pool can be processing the same customerId at any one time.

    It is step 2 that I'm really struggling with as I can't see a way for a ThreadPoolTaskExecutor to prevent execution of a message {customer1, pear} until {customer1, apple} has finished executing.

    Can anyone point me in the right direction?

    Cheers,

    James

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You want to prioritise the queue, right?
    Last edited by r035198x; 11-07-2009 at 06:43 PM.

  3. #3
    jshailes is offline Member
    Join Date
    Jan 2009
    Posts
    7
    Rep Power
    0

    Default

    Thanks for the reply. I'm not sure if prioritising the queue is the right terminology or not.

    I basically want 2 jms queues:
    1. main - this is the target from an external source
    2. priority - this is used to hold messages that cannot currently be processed due to a thread currently executing a message with the same customer id.

    A class to find the next message. In order to find the next message it will:
    1. check if anything on the priority queue can yet be processed
    2. if 1. is false or the priority queue is empty then pull the next message from the main queue
    3. if an existing thread is processing a message for the customerId of this new message from the main queue, put it on the priority queue.

    Then a thread pool. Once a thread becomes available it asks the NextMessageFinder for the next message and then processes it.

    Seems like a reasonably straightforward thing to do but I'm so confused!

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Priority Queue:

    When the customerId is active then the priority is 1; when the customerId is not in use then the priority is 0.

    When the priority is the same then it acts like a queue for that priority value.

    When a messages comes in, or a thread is released, then Peek the priority queue: if that message has a customerId that is currently processed then everything in the queue at the moment in time is currently active and nothing needs processing; otherwise poll the queue and process the task.
    Last edited by mrmatt1111; 11-06-2009 at 09:33 PM.
    My Hobby Project: LegacyClone

  5. #5
    jshailes is offline Member
    Join Date
    Jan 2009
    Posts
    7
    Rep Power
    0

    Default

    I'm sorry for being obtuse but I really don't understand how to implement this.

    When the customerId is active then the priority is 1; when the customerId is not in use then the priority is 0.
    Where is this priority stored? On the customer?

    When the priority is the same then it acts like a queue for that priority value.
    When the priority is the same as what? Where does a queue to come into it?

    Do I need to write a custom ThreadPool? They seem to have a queue built into them. I would need to customise how it uses this queue since I need 2 - currently and preferably left in Websphere MQ and accessed with JMS.

    Once again sorry if i'm being thick, I just don't grasp what you're saying Matt.

    Thankyou.

  6. #6
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    You are building a scheduler. It will have two parts: managing the messages coming in and scheduling those messages (priority queue) to the available resources (pooled worker threads running in an executor, for example).

    I would suggest spending some time figuring out how to use a priority queue works first.

    Then i would spend some time looking at Runnable and Executors like ThreadPoolExecutor.
    My Hobby Project: LegacyClone

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 05:37 PM
  2. Replies: 7
    Last Post: 10-20-2009, 10:34 AM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  4. connection pooling
    By kal132 in forum JDBC
    Replies: 1
    Last Post: 06-27-2007, 02:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •