Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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
0
hawkly
Asked:
hawkly
  • 7
  • 4
  • 2
  • +1
1 Solution
 
alikoankCommented:
No it will not kill a running thread.
0
 
objectsCommented:
> will it kill the object or thread?

neither
0
 
sciuriwareCommented:
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!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
hawklyAuthor Commented:
then how can i kill the thread when it waiting for an IO?
0
 
objectsCommented:
> 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.
0
 
objectsCommented:
> 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
0
 
alikoankCommented:
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.
0
 
hawklyAuthor Commented:
The IO is:
in = httpConnector.openInputStream();

How can i interrupt it?

thanks
0
 
objectsCommented:
you can try interrupting the thread but i suspoct you may have to close the connection.
0
 
hawklyAuthor Commented:
but my problem is how can i close the connection?
0
 
objectsCommented:
httpConnector.close();
0
 
hawklyAuthor Commented:
The program is stop at:
in = httpConnector.openInputStream();

so how is possible i trigger the httpConnector.close(); ?

thanks
0
 
objectsCommented:
> so how is possible i trigger the httpConnector.close(); ?

from a different thread.
ie. the thread that you want to stop the blocked thread from.
0
 
objectsCommented:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now