• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why the author start the app thread like this?

 
laoying Yin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sample code:

public class Server {
ServerThread thread;

private ServerThread extends Thread {
public void run() {
Server.this.run();
}
}

public Server() {
if (thread == null) {
thread = new ServerThread();
thread.start();
}
}

public void run() {
....
}

Can somebody explain for me? or give me some tips. I don't know why the author start the server like this, what's the usage of the private inner class? Is there any advantage get from this?
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call to Server constructor returns immediately and ServerThread starts in the background. Use inner class to keep it all in one handy place I guess, no other reason I can see
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic