First, let's review the definition of Singleton Pattern (emphasis mine):
In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object.
When you declare a class that implements the Filter
interface, it needs a public
constructor (usually the default constructor) so the application server could instantiate it. Thus, by doing this, the Filter
is not a singleton.
Note that the application server will maintain a single instance per application context e.g. per a deployed web application, but this is not the same as having a singleton. Why? Because you or another programmer can carelessly create an instance of this class (even if it doesn't make use of the instance).