Solved

Object / Thread FAQ

Posted on 2004-08-01
14
211 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Updating Java 9 87
strCount chalenge 3 50
for i loop in grovy 1 32
java  and programming certification ? 4 64
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now