EJB-@Singleton to manage query results

Should I use EJB-@Singleton (javax.ejb.Singleton) for statistics or monitoring, or is it better to cache statistics in general @ SessionScoped-Bean? To clear my question, here are two scenarios:

Scenario I:

The user starts a Websession and makes database queries to view statistics or data. These requests are filled in throughout the session. Thus, 10,000 users will make 10,000 identical queries to the database.

Scenario II:

The user starts the website and repeats the data for statistics or the data from the preinitialized @ Singleton-Bean. @Singleton (javax.ejb.Singleton) completed the request at the beginning of Server-Startup (@Startup). Thus, 10,000 users can read from the ONE cache (@Singleton) and should not query the database. My @ Singleton- Bean starts updating its cached data if someone else creates / edits / deletes the data.

So my questions are:

  • Scenario II scales better than scenario I? I think yes. I'm right?
  • Are there any other reservations or things to consider?
  • I know Stateless- Beans scales much more than @stateful or @Singleton. Should I use @ Stateless-Bean and cache requests with something like JPA / Hibernate Caches.
  • Should I use @ApplicationScoped (javax.enterprise.context) instead of @Singleton (javax.ejb.Singleton) to use a proxy? Would be better?
+4
source share
1 answer

Yes, scenario 2 scales better than 1, we are talking about efficiency here.

It is better to use the lower level, that is, the save level, to cache objects, simply because it is his task to do this.

Using either depends on which server you are using, you are using a full corporate server, if so, it is better to use the transactions it offers, if you just use a web container such as tomcat, and then it is better to use managed beans.

+2
source

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


All Articles