J2EE: Singleton is against keeping things in session

When should an object (i.e. an application properties file) be saved in a session, as opposed to creating a singlet to save it? When should each of these approaches be used?

Note. I am working on a clustered environment if that matters.

+3
source share
3 answers

If it should be system-wide, then it cannot be stored in the session area, but in the application area. With saving in the session area, you unnecessarily duplicate the same data for each visitor. The syntax is also not needed at all, just create an instance once during server startup using ServletContextListenerand save it in the application area using ServletContext#setAttribute().

+9
source

+1 to BalusC, but I suspect it was just a typo on your part.

As for singletones, it depends on what you mean by singleton. If you have an EJB annotated with @Singleton then this is fine (other dependency injection providers may also support this pattern).

, , . Java EE , - , , , . , , , (, ).

+2

. , .

, BalusC , , , . , , , . , , .

...

Java EE , , , .. , "Java EE " . , , , , .

Java EE , , . .

+2

Source: https://habr.com/ru/post/1764183/


All Articles