On Saturday 18 October 2003 21:07, Leo Simons wrote:
> Niclas Hedhman wrote:
> > I'm not into politics, but please explain why a "Socket Server" should
> > hang around in memory if it is not referenced?
> >
> > IIUIC, a socket server will be listening on a socket, i.e. the thread is
> > blocked, and the thread management will maintain the reference to its
> > Runnable entry and GC will not mark it as "garbage". No?
>
> I doubt that's guaranteed....
>
> class MyServer
> {
>    initialize()
>    {
>      new Thread( new Runnable { /*...*/ } ).start();
>    }
> }
>
> nothing references the thread, only the thread references the runnable,
> only the runnable references the socket, nothing references myserver.
>
> Yes, the thread management references the thread, but I think that's
> (allowed to be) a weak reference.

Guys, I thought you were better at Java than this. ;o)

Not only does ThreadGroup keeps track of which threads exists, but look up the 
setDaemon method to see the difference...

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#setDaemon(boolean)

<quote>
Marks this thread as either a daemon thread or a user thread. The Java Virtual 
Machine exits when the only threads running are all daemon threads. 
</quote>


Cheers
Niclas

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to