The Artima Developer Community
Sponsored Link

Java Answers Forum
Killing Threads

2 replies on 1 page. Most recent reply: Jul 22, 2005 3:58 AM by Slager .

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Killing Threads Posted: Jul 12, 2005 3:55 AM
Reply to this message Reply
Advertisement
Hi again:

Am I right in assuming that if I null a Thread,
it is cleaned up by garbage collection thus
in effect killed? I understand, they actually
persist, but an article by Bill Verners on JavaWorld
claims that when objects have no reference they
are cleaned up by the garbage colletor.

Please help me understand this because I'm
writing an app, for which if I keep nulling
my Threads and they aren't exactly cleaned up,
my application will turn nasty really fast.

Thanks in advance.

Spike


Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: Killing Threads Posted: Jul 12, 2005 3:12 PM
Reply to this message Reply
Really it is : "when objects have no reference they might
be cleaned up by the garbage colletor at any time".

A null Thread will be running until the garbage collector decides to make some clean. Even if you invoke
System.gc()
you will have no warranties about what was or wasn't cleaned. The System doesn't promises to recover all the space, but to make some space.

Slager .

Posts: 16
Nickname: slager
Registered: May, 2003

Re: Killing Threads Posted: Jul 22, 2005 3:58 AM
Reply to this message Reply
Nulling a thread reference does not cause the thread to stop running.

Threads are obviously a special type of object. After starting they are under control of the VM so they can be executed. The VM will hold references to the thread until it stops running. You can receive a list of threads active in the VM via the Thread class itself.

Killing a thread is not really possible unless you design for it in your thread code. Two general ways to investigate are the interrupt() method and relatives from Thread or implementing a simple boolean stop value.

Flat View: This topic has 2 replies on 1 page
Topic: Advantages/Disadvantages/Performance using Applet vs JSP Previous Topic   Next Topic Topic: ThreadPoolExecutor and ArrayBlockingQueue

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use