• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main app won't stop when all threads are done running

 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class that extends Thread. The main method of this class just starts a thread which starts other threads. The number of threads varies based on a "properties" file. When all of the threads complete, I want the program to stop. I'm already calling join on the original thread started by main and interrupt on the other threads. It works perfectly when the app runs cleanly. Yet when the application throws a NullPointerException (I don't know about the case of other exceptions) in one of the child threads, the main app does not stop.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if there is enough information here as it could be a number of things... for example...

While a NPE can unwind the stack of the child thread and effectively release any locks it held, the state of the data may be in a state the other threads can't handle (and may go into a state where they don't return)

You may be using some sort of flag, which is expected by other threads to be set to a value, which won't be done if the thread that is processing exits unexpectedly.


As for interrupt, that only works if the child threads are designed to receive them and act accordingly. If it isn't designed to check, all you get is more bugs.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, you can also take a thread dump of the JVM, once the NPE occurs, to see just what threads are still running -- and where they are running.

Henry
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a thread dump, but I'm not sure how helpful it is. They all seem to be sys_thread_t and most are in a wait state. Is there something I'm missing here?
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While a NPE can unwind the stack of the child thread and effectively release any locks it held, the state of the data may be in a state the other threads can't handle (and may go into a state where they don't return)

I'm not sure I'm following you here. What sort of state could the data be in (for example) that would cause this?

You may be using some sort of flag, which is expected by other threads to be set to a value, which won't be done if the thread that is processing exits unexpectedly.

Possibly, but I don't think so. At least if that's the case, it's not obvious to me.

As for interrupt, that only works if the child threads are designed to receive them and act accordingly. If it isn't designed to check, all you get is more bugs.

Again, this could be, but it's not obvious to me. I'll keep looking.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need the join in the main thread?

What are the BoundedLinkedQueues waiting for?
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn,

It looks like you are using Doug Lea's concurrent library. Maybe a threadpool (or some other type of executor). Something related with the message queues.

I have practically *no* experience with this library (as I wrote my own with Java 1.4 and eariler), but I am guessing that NPE is messing something up with that library. Those threads are not terminating, and hence, the main thread is not exiting.


Don't really have an answer here... except maybe look into preventing that NPE from happening, or finding some way to catching it earlier so that it can cleanly exit, and not corrupt something higher up in the stack.

Henry
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
Why do you need the join in the main thread?

What are the BoundedLinkedQueues waiting for?


I think his idea was to join all the threads before main was allowed to complete, but it's not working that way.

BoundedLinkedQueues are message queues. They're not threads, so I thought it was IO blocking.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:
It looks like you are using Doug Lea's concurrent library. Maybe a threadpool (or some other type of executor). Something related with the message queues.

I have practically *no* experience with this library (as I wrote my own with Java 1.4 and eariler), but I am guessing that NPE is messing something up with that library. Those threads are not terminating, and hence, the main thread is not exiting.


We're using the EDU.oswego.cs.dl.util.concurrent package with java 1.3. But thanks for all the info. It's been very helpful.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn de Queiroz:
BoundedLinkedQueues are message queues. They're not threads, so I thought it was IO blocking.


Well, from their Javadocs I get that they are using some "help monitors", from which I assume that they are using threads internally.

I also don't think that Object.wait is used in IO blocking.

What does the stacktrace of the NPE look like?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic