|
|
|
|
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.
|
|

05-07-2008, 09:55 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 12
|
|
|
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)
|
|

05-07-2008, 10:02 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
|
|
|
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
|
|

05-07-2008, 10:08 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 12
|
|
|
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?
|
|

05-07-2008, 10:48 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
|
|
|
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
|
|

05-07-2008, 10:58 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 12
|
|
|
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)...
|
|

05-07-2008, 11:00 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 12
|
|
|
Yes, it is in java
|
|

05-07-2008, 11:33 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
|
|
|
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
|
|

05-07-2008, 11:56 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 12
|
|
|
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?
|
|

05-07-2008, 11:59 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
|
|
|
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
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
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