Solved

Object / Thread FAQ

Posted on 2004-08-01
14
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 57
String array comparison 4 45
Cisco ASA: Java web start no go, asdm launcher no go 3 57
maven not picking latest jar instead picking old jar from .m2 12 44
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 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