Solved

Object / Thread FAQ

Posted on 2004-08-01
14
235 Views
Last Modified: 2010-03-31
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
Comment
Question by:hawkly
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 4

Expert Comment

by:alikoank
ID: 11691203
No it will not kill a running thread.
0
 
LVL 92

Expert Comment

by:objects
ID: 11691237
> will it kill the object or thread?

neither
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 11691262
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:hawkly
ID: 11691313
then how can i kill the thread when it waiting for an IO?
0
 
LVL 92

Expert Comment

by:objects
ID: 11691314
> 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
 
LVL 92

Expert Comment

by:objects
ID: 11691319
> 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
 
LVL 4

Expert Comment

by:alikoank
ID: 11691341
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
 

Author Comment

by:hawkly
ID: 11691378
The IO is:
in = httpConnector.openInputStream();

How can i interrupt it?

thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 11691406
you can try interrupting the thread but i suspoct you may have to close the connection.
0
 

Author Comment

by:hawkly
ID: 11691821
but my problem is how can i close the connection?
0
 
LVL 92

Expert Comment

by:objects
ID: 11691904
httpConnector.close();
0
 

Author Comment

by:hawkly
ID: 11699943
The program is stop at:
in = httpConnector.openInputStream();

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

thanks
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 11699961
> 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
 
LVL 92

Expert Comment

by:objects
ID: 11712445
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question