Reputation: 2057
I have a session bean in JSP, and in that bean I am starting a thread that sleeps for 10 sec and executes again. The problem I am facing is, after logging out also this thread continues to run.
Can someone please help how to stop that from running?
Upvotes: 0
Views: 1651
Reputation: 1546
According to the EJB specification, starting threads from EJBs is illegal. Cf. section 21.2.2 (page 593):
"The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread, or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups."
There may be a different solution using EJB or you may need to use a different framework. This depends on what exactly you are trying to accomplish.
Upvotes: 1
Reputation: 1540
Starting threads out of servlets is not a good idea because you may ran out of resources (memory and CPU) if you have many users. Especially with database access strange behaviour will occur!
Add a Quartz timer (http://quartz-scheduler.org) that triggers every 10secs and processes a list where your session beans have beed subscribed. On user logout unsubscribe your bean from your service again.
Upvotes: 0