• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to reduce the CPU usage when thread is running.

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic