File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Thread Stops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Stops" Watch "Thread Stops" New topic

Thread Stops


Joined: Mar 13, 2001
Posts: 19
I am having one peculiar issue.
I am having four threads running in one Thread group.
I am storing the status of each thread in one ThreadStorage class file which ofcourse is a singleton class.So once it is initialised the status is set to on and threads are started running.Now each thread performs some business logic.All above is running at my remote server(Linux8.0).
But the problem is that sometimes the threads are killed without our knowledge.I have provision to monitor the status of thread and entering the details in the log file.But i do not find any reason how the threads killed prematurely.
I hv provision to start ,stop and kill all the threads using JSP page.
Can anyone suggest the reason for the occasional failure of the threads?
Tiberiu Paun

Joined: Sep 02, 2003
Posts: 10
Please excuse my poor knowledge, in case u already tried what I will suggest.
1. A thread can die suddenly most probably because there was a RuntimeException (NullPointerException, NumberFormatException, etc) inside run() method.
I would suggest you to write this :
public void run(){
//business logic
}catch(Throwable t){
Hope this might help u.
2. On the other hand, from my poor knowledge, ThreadGroup class is not worth it.
When you use threadgroup , u start threads. starting a thread is pretty much slower than having the threads in a pool. U use ThreadGroup because probably u are interested in knowing when all those threads have stopped, and u'll have to do a loop (with sleep in it) to see how many active threads are inside this ThreadGroup. You can put this very easy (with a lot of code, of course) with a pool of threads, and would be a lot more faster (because of the pool and because when all those threads have finished a cycle in run -in run u have an endless loop, from which u can exist only when u want- u'll get a notify).
Hope u got what I said here, and, again, please excuse my poor knowledge in case I misslead u in any way.
Best regards, Tibi.
Best regards, Tibi.
I agree. Here's the link:
subject: Thread Stops
It's not a secret anymore!