Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to reduce the CPU usage when thread is running.

 
Balaji Soundarajan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using thread concept for my application development, when i am trying to execute the thread it hast to listen form 120 seconds for check whether any command is came for process or not, during the 120 seconds the my CPU usage was very high, i have to reduce the utilization of the CPU usage.

Please do the needful

Regards
-Balaji.S
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what kind of job your thread does ? its doing some kind of IO operation ? then the CPU usage might go up. Not sure if you can reduce it using your code.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably you're doing something like



Don't do that -- it does, indeed, use lots of CPU time. Instead use wait() and notify(). There's a form of wait() that takes a wait time as an argument, which could be helpful.
 
Balaji Soundarajan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Here i don't want to make the thread to wait status, it has to monitor the command from the client simultaneously for 120 seconds with out using CPU usage.

Thanks
--Balaji.S
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balaji Soundarajan wrote:
Here i don't want to make the thread to wait status, it has to monitor the command from the client simultaneously for 120 seconds with out using CPU usage.


That's exactly what wait/notify is for. The command thread calls wait() on some object. Then when a message arrives from the client, the client thread calls notify() on that same object. The command thread gets the notification and wakes up, processes the command, and calls wait() again to wait for another command.
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. You got to wait until the command comes from the client. once the command reaches, you can notify your waiting thread so that it can process the command.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic