• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Thread Stops

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This tiny ad is wafer thin:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic