hawkly
asked on
Object / Thread FAQ
My program as follow:
mainProgram.java
newThread= new myThread("Testing");
In the myThread.java :
public class myThread implements Runnable {
My question is if i write the newThread = null will it kill the object or thread?
E.g.
newThread= new myThread("Testing");
newThread = null ;
thanks
mainProgram.java
newThread= new myThread("Testing");
In the myThread.java :
public class myThread implements Runnable {
My question is if i write the newThread = null will it kill the object or thread?
E.g.
newThread= new myThread("Testing");
newThread = null ;
thanks
No it will not kill a running thread.
> will it kill the object or thread?
neither
neither
An object is never deleted by "killing" a reference to it.
An object is deleted by the garbage collector at a later time.
And, surely a running thread is referenced from various other places!
;JOOP!
An object is deleted by the garbage collector at a later time.
And, surely a running thread is referenced from various other places!
;JOOP!
ASKER
then how can i kill the thread when it waiting for an IO?
> And, surely a running thread is referenced from various other places!
The thread above is not running, and so would be available for gc.
So the object *could* get freed at a later time.
The thread above is not running, and so would be available for gc.
So the object *could* get freed at a later time.
> then how can i kill the thread when it waiting for an IO?
you interrupt it (if the blocking is interruptable.
otherwise one solution is to close the stream the thread is being blocked on
you interrupt it (if the blocking is interruptable.
otherwise one solution is to close the stream the thread is being blocked on
Generally speaking you should not kill a thread. Make your thread check for a variable or event periodically and when you want your thread to terminate set this variable / signal an event, so your thread can end its execution gracefully.
ASKER
The IO is:
in = httpConnector.openInputStr eam();
How can i interrupt it?
thanks
in = httpConnector.openInputStr
How can i interrupt it?
thanks
you can try interrupting the thread but i suspoct you may have to close the connection.
ASKER
but my problem is how can i close the connection?
httpConnector.close();
ASKER
The program is stop at:
in = httpConnector.openInputStr eam();
so how is possible i trigger the httpConnector.close(); ?
thanks
in = httpConnector.openInputStr
so how is possible i trigger the httpConnector.close(); ?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.