Solved

Object / Thread FAQ

Posted on 2004-08-01
14
240 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

808 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