Results 1 to 6 of 6
Thread: Thread Pooling
- 11-06-2009, 03:00 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 6
- Rep Power
- 0
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
- 11-06-2009, 07:16 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You want to prioritise the queue, right?
Last edited by r035198x; 11-07-2009 at 06:43 PM.
- 11-06-2009, 05:10 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 6
- Rep Power
- 0
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!
- 11-06-2009, 09:30 PM #4
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
- 11-06-2009, 09:47 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 6
- Rep Power
- 0
I'm sorry for being obtuse but I really don't understand how to implement this.
Where is this priority stored? On the customer?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 as what? Where does a queue to come into it?When the priority is the same then it acts like a queue for that priority value.
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.
- 11-06-2009, 11:36 PM #6
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
-
Difference between Thread.yield() and Thread.sleep() methods
By Nageswara Rao Mothukuri in forum New To JavaReplies: 12Last Post: 07-30-2010, 05:37 PM -
we implement connection pooling ourselves, but why it always out of connection ?
By zengqingyi12 in forum JDBCReplies: 7Last Post: 10-20-2009, 10:34 AM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM -
connection pooling
By kal132 in forum JDBCReplies: 1Last Post: 06-27-2007, 02:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks