Application-Scoped Object and Singleton Classes

As you design your application, you're going to find that most of the Beans that you use are session-scoped. You might find the occasional use for a request-scoped Bean, one that stays around only as long as the current request, but they're usually few and far between.

If you find yourself using application-scoped Beans, you might want to consider using a singleton class to map the object into the local session. A singleton has the advantage that only one copy can ever exist in a virtual machine, even if you accidentally throw away the reference to it. In contrast, you can create multiple instances of a class at the application level if you inadvertently use different ID names for the useBean. Singletons ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.