[jboss-user] [Newbie] Custom thread inside JBoss

Kamil Burzynski nopik at data.pl
Mon Aug 11 14:08:12 EDT 2008


Hello,

  First of all, I'm new to EJB and JBoss, so please be gentle ;)
My question is quite popular I think - I have searched google for long 
time, found few discussions on the topic, but did not found any useful 
reply.

  The issue is this: I need to create custom thread inside JBoss and 
communicate with it quite heavily (like few hundred messages per 
second). I know that EJB spec says I should not try this. While it is 
forbidded, it still seems that many users do that. My question is: how 
to do it in a most safe way? Or just in a 100% safe method, if such exists?

  Since I'm upgrading from JSP/servlet application, easiest solution for 
me would be to:
- create custom servlet which does start my thread in the init time
- the thread does send JMS messages and receive them, no direct 
communication between EJBs and this thread is done
- when servlet gets undeployed, shut down thread as well

  For my, newbie, understanding of EJB, this should be safe enough. Yes, 
JBoss wont be able to control my thread, but, things should be safe.
Am I right? What problems I am missing?

  I have tried to put the thread outside JBoss and communicate via JMS - 
it worked, though performance was not acceptable. I need more 
performance.. so side question: how to get most performance in JMS in 
two cases:
a) between separate vm processes
b) inside one vm process
?

Why I need the thread in the first place? Well, my jsp application does 
some realtime stock quote processing. I have external library, which 
does open some threads and sends notifications to me (e.g. about price 
change). So, when I deploy my app to Tomcat, there is context listener 
class which does initialize things in init time. Then, threads started 
internally by this library starts to send notifications to my servlets. 
When some JSP is invoked, I just communicate with servlets and 
everything is working flawlessly. Now, I have to move this to JBoss. I 
think that if I would leave the code in servlet, it still would work ok. 
Am I right? But, of course, cleaner solution will be to move this code 
out of servlet and put directly inside JBoss (not using EJB here, just 
for safety), add some EJBs and go on with the implementation.

-- 
Best regards from
Kamil Burzynski



More information about the jboss-user mailing list