| Author |
Creating a control for processing speed
|
Gagan Tiwari
Ranch Hand
Joined: Jun 10, 2008
Posts: 68
|
|
Hi
I have developed a program whose task is to read teh messages from the queue and then distribute it to the diffrent system
Its just reading a Message and sending it to the underlying system.
However I need to enhance this component with a SPEED CONTROL type of thing.
Say I am able to process X Message per second in normal case.
If I reduce the speed control then the processing should be 0.8X Message per second.
If I reduce the speed control again then the processing should be 0.6X Message per second.
Any idea on how we are going to acheive this?
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1409
|
|
When you' say "the queue" and "the message", are you talking about JMS, some 3rd party messaging system, or your own custom producer/consumer implementation?
|
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
|
 |
Gagan Tiwari
Ranch Hand
Joined: Jun 10, 2008
Posts: 68
|
|
|
Yes I means JMS when talking Message.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
You keep track of how many messages you have processed in a certain time period. From there some simple arithmetic gives you the number of messages per second. If that's above your limit then call the Thread.sleep() method to sleep for a certain amount of time. How much time? More simple arithmetic.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
You should look at the java.util.concurrent.Semaphore class. It allows a kind of throttling by limiting the number of threads that can access a resource.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
 |
|
|
subject: Creating a control for processing speed
|
|
|