Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Destroy session beans from application scoped bean  RSS feed

 
antoine torres
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!

I have a problem that I don't manage to solve.
I'm developping a web application with JSF under Eclipse / Tomcat.
This application contains an application scoped bean that manages all initialisation stuff and several session beans that manage parts of the application.
I realized that when the application was stopped in the tomcat manager, several threads launched in the application scoped bean were still alive, so I coded a @PreDestroy method in order to stop and free all existing threads.
It works fine.
However, the session beans are not correctly destroyed, as they still are writing traces after the application stops.
I tried then to destroy manually the opened sessions in my @PreDestroy method, using the following code :

Or :

using the following sessionListener class :


but both of these methods throw the following exception:


Does somebody have an idea of what i am doing wrong?
Is there a better way to correctly handle applicationscoped and sessionscoped beans destruction?
Thanks in advance
 
antoine torres
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
up?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally we discourage "bumps". But for some reason, I must have missed the original posting. Either that or you were using an invalid display name at the time, since I don't respond to questions from people using invalid display names.

I hope that you are not spawning threads in JSF code. J2EE expressly forbids any sort of thread spawing in HTTP Request-handling code, and that includes JSF code.

Actually, I just realized that you said you were. Don't!

If you need to spawn threads, spawn them in a ServletContextListener, not in a JSF bean, regardless of scope. And make sure that the shutdown method of that listener terminates all those threads, Don't anchor those threads in a JSF backing bean. You could potentially orphan them and not be able to find them when they're needed.

If you spawn threads in J2EE request-handling code, you can potentially crash the entire webapp server, in addition to whatever other grief you may encounter. It might run fine for months, or even years, but Murphy's Law works here. When it does screw up, you can pretty much bet it will do so royally.
 
antoine torres
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks for the explanations!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!