This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Stops" Watch "Thread Stops" New topic
Author

Thread Stops

Ramamoorthy
Greenhorn

Joined: Mar 13, 2001
Posts: 19
Hi,
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?
Regards,
Ram
Tiberiu Paun
Greenhorn

Joined: Sep 02, 2003
Posts: 10
Hi.
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(){
try{
//business logic
}catch(Throwable t){
Log.log(log_trace,t.toString());
}
}
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: http://aspose.com/file-tools
 
subject: Thread Stops
 
Similar Threads
what is a Daemon Thread
Some questions!!!
a question on multithreading
Master Worker Thread model
Thread Locks