0

Is there a way to give the threads that run in EJBs a name so they can be identified in the thread list in VisualVM? Threads call timer (@Timeout) and JMS (onMessage()) methods as well as http servlets methods.

Currently, the threads are given generic names such as:

http--0.0.0.0-443-3
or
EJB default - 9

I currently use :

Thread.currentThread().setName("Checker thread") 

at the beginning of these methods, but I'm not sure it is always working in VisualVM so am looking for additional ideas.

Dharmesh Porwal
  • 1,406
  • 2
  • 12
  • 21
AlJo
  • 161
  • 1
  • 13

1 Answers1

0

In the @PostConstruct method of the EJB I use the same Thread statement you do.

You might also think about placing it in a class level interceptor and use the invocation context to get the name of the EJB and name the thread accordingly at that point.

NBW
  • 1,467
  • 2
  • 18
  • 27
  • You can't put it in the @PostConstruct and set the name permanently b/c the thread could be reused for a completely different task elsewhere in the container and so the name will be misleading when looking at a stack dump. I didn't say, but I have to reset the name to its original name before leaving the method. – AlJo Jan 07 '15 at 06:49
  • @AlJo that hasn't been my experience with glassfish. What container do you use? – NBW Jan 07 '15 at 09:07
  • JBoss. It's certainly probable since the threads come from a thread pool - for the usual cases - and there's no guarantee which one from the pool will be chosen to run a particular method each time. – AlJo Jan 08 '15 at 03:14