From: Shapira, Y. <Yoa...@mp...> - 2003-12-11 15:50:16
|
Howdy, >It seems simple enough except for one thing. The last line returns right >away. Afterwards, the variable "server" goes out of context and is >available to be gc'ed. Your reference to the server can be GCed. If other threads are holdin= g references to it, than the server will not be GCed. >After that, "main" ends and so should this program. >However, in reality the server is working just fine. What's going on?= I >understand that the server may be spinning off other threads, etc, bu= t once >a program terminates, that's the end. Sorry if this is a stupid question, >but I've never seen anything done like this before (maybe something >peculiar to Java??). The JVM will keep running as long as non-daemon threads are running. = If I had to guess, I'd say you're creating a non-daemon thread to run the= server. So that when the main thread exits, the server thread and therefore the JVM stays running. The JavaDoc for java.lang.Thread explains more. Yoav Shapira This e-mail, including any attachments, is a confidential business com= munication, and may contain information that is confidential, propriet= ary and/or privileged. This e-mail is intended only for the individua= l(s) to whom it is addressed, and may not be saved, copied, printed, d= isclosed or used by anyone else. If you are not the(an) intended reci= pient, please immediately delete this e-mail from your computer system= and notify the sender. Thank you. |