Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Object / Thread FAQ

Posted on 2004-08-01
14
Medium Priority
?
260 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 200 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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.

688 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