This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths 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 Head First Android 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>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why the author start the app thread like this?
 
It's not a secret anymore!