Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a control for processing speed  RSS feed

 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I means JMS when talking Message.
 
Paul Clapham
Sheriff
Posts: 22838
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!