Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2008, 09:55 AM
Member
 
Join Date: May 2008
Posts: 12
byuu is on a distinguished road
help with networking and threads
is there anyway to make this implementation more efficient?


The implementation is:

There is this method thread that has an infinite loop which waits for connections and accepts it if there's one. The implementation is hungry of CPU usage. is there anyway to slow down the CPU usage? like setting up a timeout for the infinite loop, etc. (i'm not quite sure about the timeout thing)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-07-2008, 10:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Normally it can be happened, because of the loop. I can't say more about without having exact idea what your application do.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 10:08 AM
Member
 
Join Date: May 2008
Posts: 12
byuu is on a distinguished road
ahh. i see.

well, we are currently making a customized Server-Client instant messenger. and the server (the one that handles connections) is the one that has the infinite loop waiting for connections. is there anyway to lessen the CPU usage by any other means?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 10:48 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Rather using an infinite loop, can you make a request from the client in specific intervals? In that case, only the requesting time CPU usage is high.

Is that server written in Java?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 10:58 AM
Member
 
Join Date: May 2008
Posts: 12
byuu is on a distinguished road
would having an infinite loop that sleeps at specified intervals achieve the same result that you have described?.. im assuming the cpu usage would lessen when the thread sleeps (timeouts)...
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-07-2008, 11:00 AM
Member
 
Join Date: May 2008
Posts: 12
byuu is on a distinguished road
Yes, it is in java
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-07-2008, 11:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yep it should be, if the thread sleep CPU usage should be lesser. Didi you use more than one thread, if so how did you handle them?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-07-2008, 11:56 AM
Member
 
Join Date: May 2008
Posts: 12
byuu is on a distinguished road
thanks... i yes i used multiple threads, the threads sleep for a specified timeout time.. ive set the timeout time to around 10 milliseconds... is that okay?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-07-2008, 11:59 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I don't think 10 millisecond is enough. Can't you do it at least within 1 second. And also, did you synchronized any of thread.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads and Timeout in Socket Networking byuu Threads and Synchronization 1 05-07-2008 03:23 PM
Java networking. tim New To Java 6 01-05-2008 07:31 PM
Java networking programming (II) Java Tutorial Java Tutorials 0 12-27-2007 07:19 PM
Java networking programming (I) Java Tutorial Java Tutorials 0 12-24-2007 08:21 PM
Multithreading + Networking (desperate) bluebarca New To Java 1 11-07-2007 03:14 PM


All times are GMT +3. The time now is 06:27 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org