M
Mark McKay
I've written a small thread which calls another object to listen to a
socket, and report back anything it hears. At the moment, the thread is
spending most of it's time in the other object (let's call it
SocketListener), blocked and waiting for the socket to yeild information.
Currently, this thread will run into explicitly closed. To program
defensively, I would like to have my thread automatically close if it is
the only object that still has a reference to SocketListener (most of
the time, a second object will have a hard reference to SocketListener).
While I can partially accomplish this by turning my thread's reference
to SocketListener into a WeakReference, since my thread is still
spending most of it's time blocked inside SocketListener, I'm thinking
the garbage collector will never detect this and my thread will be
running until the program shuts down.
Am I correct thinking this? Is there an elegant way around this?
Mark McKay
socket, and report back anything it hears. At the moment, the thread is
spending most of it's time in the other object (let's call it
SocketListener), blocked and waiting for the socket to yeild information.
Currently, this thread will run into explicitly closed. To program
defensively, I would like to have my thread automatically close if it is
the only object that still has a reference to SocketListener (most of
the time, a second object will have a hard reference to SocketListener).
While I can partially accomplish this by turning my thread's reference
to SocketListener into a WeakReference, since my thread is still
spending most of it's time blocked inside SocketListener, I'm thinking
the garbage collector will never detect this and my thread will be
running until the program shuts down.
Am I correct thinking this? Is there an elegant way around this?
Mark McKay