Results 1 to 10 of 10
  1. #1
    byuu is offline Member
    Join Date
    May 2008
    Posts
    15
    Rep Power
    0

    Default 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)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Normally it can be happened, because of the loop. I can't say more about without having exact idea what your application do.

  3. #3
    byuu is offline Member
    Join Date
    May 2008
    Posts
    15
    Rep Power
    0

    Default

    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?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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?

  5. #5
    byuu is offline Member
    Join Date
    May 2008
    Posts
    15
    Rep Power
    0

    Default

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

  6. #6
    byuu is offline Member
    Join Date
    May 2008
    Posts
    15
    Rep Power
    0

    Default

    Yes, it is in java

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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?

  8. #8
    byuu is offline Member
    Join Date
    May 2008
    Posts
    15
    Rep Power
    0

    Default

    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?

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Dear cedf128,

    This forum is going on with English. I don't think we can communicate other than in English. So it's better to move with it. If you are not much familiar with English, better to ask some one else of your friend and posting here.

    Thanks.

Similar Threads

  1. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 10:43 PM
  2. Threads and Timeout in Socket Networking
    By byuu in forum Threads and Synchronization
    Replies: 2
    Last Post: 05-27-2008, 09:05 PM
  3. Java networking programming (II)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-27-2007, 06:19 PM
  4. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 07:21 PM
  5. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 02:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •