• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cut cpu-load while client is running  RSS feed

 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I want that the connection from client to server is alive, until the user close the connection. The client has to read the data all time. I've realized this with an endless-loop. But then, after I'd start the client, the cpu-load was 99%. I don't think that's the way it should.
So here my question. Is there a possibility to cut the cpu-load?
Thanks
Lars
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start a Thread reading data on the client side. Inside your read loop, just let the current Thread hold for a little while, by doing:
Thread.sleep ( 10 );
This will sleep the current Thread for 10 milliseconds, and your CPU usage will fall to almost zero, while not affecting responsiveness too much (this can be controlled by sleeping longer or less milliseconds) ...
Hope this helps.
G´┐Żnther.
www.javacoding.net
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks 4 ur help, i'll test it soon, i'll post if thats work
Thanks
Lars
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i'd test it now with sleep and it works!!
Thank you very much for your help!!!
Lars
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!