Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Orphan Thread - how to close

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Thanked 0 Times in 0 Posts

    Default Orphan Thread - how to close

    I have a program running 2 threads; occasionally the main thread stalls and the worker thread is leaft as an orphan.

    How do I close / terminate this orphan thread?

    I tried putting a simple time check in the worker thread forcing it to return after a certain elapsed time ( of zero activity from the main thread). But i still suspect the orphan thread is running.

    1) Is there a way to check if a thread is still active?
    2) Is it necessary to do more than simply return from a thread function to terminate the worker thread? ( after all an orphan has nowhere to return to)

    I am Running Ubuntu Linux 12.04, and using NetBeans as the IDE + latest Java.



  2. #2
    Join Date
    Jun 2012
    Uppsala, Sweden
    Thanked 1 Time in 1 Post

    Default Re: Orphan Thread - how to close

    Im sorry but I am not familiar enough with the java language to answer your questions, however I do now that there is a Thread.interrupted() method that returns true if the currently executing thread has been asked to interrupt its execution, that may be helpful, but once again I do not know for sure!

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    My Mood
    Thanked 140 Times in 135 Posts

    Default Re: Orphan Thread - how to close

    What happens if you set the worker Thread as a daemon thread via the Thread method, setDaemon(true)?

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Orphan Thread - how to close

    Using daemon threads only works if all non-daemon threads actually terminate, not if they stall.

    I'm unfamiliar with the Netbeans IDE, but I would be surprised if it didn't have a stack trace monitor tool you can use to identify which threads are running.

    Here's an example stack trace monitor (this is from Eclipse):


  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    My Mood
    Thanked 263 Times in 232 Posts

    Default Re: Orphan Thread - how to close

    occasionally the main thread stalls
    This sounds like a pointer to the real problem.

    What do you mean by stall? What options may be available in catching the main thread before or during the stall?
    How many threads are you dealing with? Is it just one main thread and a worker or two or something more complex?
    Provide as many details as possible...

Similar Threads

  1. Creating a close button
    By Zomby in forum Java Theory & Questions
    Replies: 13
    Last Post: October 17th, 2012, 04:13 AM
  2. Replies: 4
    Last Post: June 15th, 2012, 01:50 PM
  3. Is this correct.Am I close? Help please
    By eagle09 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 26th, 2011, 07:26 AM
  4. Trying to add a close button
    By coyboss in forum Java Theory & Questions
    Replies: 5
    Last Post: February 12th, 2011, 03:28 PM
  5. [SOLVED] How to close all tabs in JTabbedPane?
    By LeonLanford in forum AWT / Java Swing
    Replies: 7
    Last Post: June 28th, 2010, 10:58 AM