This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes why the author start the app thread like this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "why the author start the app thread like this?" Watch "why the author start the app thread like this?" New topic
Author

why the author start the app thread like this?

laoying Yin
Greenhorn

Joined: Sep 17, 2002
Posts: 20
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

Joined: May 11, 2005
Posts: 142
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


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why the author start the app thread like this?
 
Similar Threads
Redirecting Proxy Server request...
ServletContextListener & Threads
client / server (communication problem...)
Socket.close(): Where to put it
Networking question