title: After starting a thread how could we keep the run function running? I have bunch of ideas but I'm not sure which is more professional?
body: <p>In a <code>Thread</code> After calling the <code>start()</code> as you know it will call the <code>run()</code> function in the <code>Runnable</code> class. In the <code>run()</code> function I want the thread stays as long as it receive the "Bye" message from the client. If i put them in the while loop it takes heaps of memory i think and I'm not using the power of thread. By the way i don't want my thread sleep in the run function by calling <code>Thread.sleep(6000);</code> Is there any other way to stay there in the run function? </p>
  
  <ol>
  <li><p>If the answer is join where and how and use it? Should I pop it at the beginning of the run function and it stays there until I send the "Bye" from client?</p></li>
  <li><p>Should I say <code>while((request=in.readLine())!=null){</code>? It did not work because I think it will lose the connection with the client or better say client losing the connection?</p></li>
  <li><p>Should I say <code>while(Thread.isAlive)</code> and then kill the threat when I receive the "Bye" by calling <code>Thread.stop</code> which is little bit dangerous? </p></li>
  </ol>
  
  <p>Here is my simplified code: </p>
  
  <pre><code>while(true)
          {   
              ClientWorker w;
              try
              {                   
                  w = new ClientWorker(serverSocket.accept());
                      Thread t = new Thread(w);
                      t.start();
                  }
  ......  }
  
      class ClientWorker implements Runnable {
          public ClientWorker(Socket incoming)
          {
              myList = my;
              this.incoming = incoming;
          }
      public synchronized  void run()
      {
           in = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
  .
  .
  ..
  ...
  }
  </code></pre>