kiriappa
kiriappa

Reputation: 832

how to manage CPU resources

In a producing and consuming application, let's say producting takes one cpu cycle and consuming takes 3 avarage cpu cycles. Then how do we manage to keep equal number of productions and consumptions boundry. this is a problem I imaginge while I was studying threads.

If you have any idea to implement this with Java please share your knoweledge.

Upvotes: 0

Views: 75

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533442

You have to design your system so that you consumers can keep up with your producer in the long run. Most producers are bursty and if you use a queue it doesn't matter that for very short periods they are producing faster than your can consume. If this is not the case you can

  • have multiple consumers.
  • drop or combine produced messages to reduce the load on the consumer.
  • push back on the producer to slow down.

Upvotes: 3

Related Questions