Paul Clapham wrote: ...then you should be putting them in application scope rather than in session scope...
Paul Clapham wrote:Execute code on webapp startup and shutdown using ServletContextListener
To that I would add: from the ServletContextEvent object passed to the contextInitialized method you can get a ServletContext; to add an object to application scope you can call its setAttribute(name, object) method. Elsewhere in your app you can easily get a ServletContext and call getAttribute(name) to retrieve that object, or in JSTL it's very easy to access objects in application scope.
Paul Clapham wrote:... from the ServletContextEvent object passed to the contextInitialized method you can get a ServletContext; to add an object to application scope you can call its setAttribute(name, object) method.
Bear Bibeault wrote:ServletContext.getAttribute()
Of course, you've got to put it there first.
Think about it, of what use is sticking it into a member variable of the listener? You want to put all your "global" data into the application context (aka ServletContext).
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:Long before there were webapps, or for that matter, even the Internet, I learned the hard way that global variables can be a real nightmare. So keep them to a minimum.
Steve Dyke wrote:
Tim Holloway wrote:Long before there were webapps, or for that matter, even the Internet, I learned the hard way that global variables can be a real nightmare. So keep them to a minimum.
Thanks for the insight. My quest is to reduce the number of objects having to be created on the heap. I have "Out of Memory" issues from time to time. I thought that minimizing the number of times a class is constructed might help.
My JVM is set to 3G already. My compiled app(deployed) size is almost 1G. The app will run for several days even a week or more then the heap size grows beyond the max.
Steve Dyke wrote:In the log on servlet
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:
Steve Dyke wrote:In the log on servlet
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |