Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store a Servlet's singletons?

If my Servlet class uses a singleton (such as a manager class), where should it be stored? The servlet itself, or in the ServletContext?

Can a servlet container create more than one instance of my Servlet class to handle requests?

like image 551
Tony the Pony Avatar asked Feb 25 '23 18:02

Tony the Pony


1 Answers

It is certain that there will be only one instance of a Servlet. But still, it's better to store it in the ServletContext. Thus it will be accessible from other servlets as well.

like image 167
Bozho Avatar answered Mar 12 '23 07:03

Bozho