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

    Default Threads and Timeout in Socket Networking

    Question:

    does creating a timeout in a thread that loops infinitely would help in reducing the lag or CPU usage?

    The Implementation is this:

    we have a method thread that loops infinitely waiting for a connection. but it costs a lot of CPU usage. is there any way to decrease it's CPU usage? possibly by creating timeouts of the thread? or is there in any way to efficiency of the code?

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Don't make the thread loop infinitely, make it wait until it is notified the connection is there.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    gogoc is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    you can add some sleep in between the loop so that it waits for some time or if a listener is available then you can go for listener
    thread notify and wait is also helpful

Similar Threads

  1. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 10:43 PM
  2. Java networking programming (II)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-27-2007, 06:19 PM
  3. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 07:21 PM
  4. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 02:14 PM
  5. Detect TimeOut in a HttpURL Connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 04:29 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
  •