Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ApplicationScoped in a cluster

I don't have a clustered environment at present, but I was curious about @ApplicationScoped behaviour in a clustered environment. Is there going to be only one across the cluster or is still still one per JVM in the cluster?

I have read that @Singleton gets created per JVM in

How singleton is javax.ejb.Singleton in a clustered environment?

like image 607
Archimedes Trajano Avatar asked Aug 18 '15 02:08

Archimedes Trajano


2 Answers

@ApplicationScoped beans are not replicated per se.

There may be some containers or servers replicating those beans, but it is not part of the CDI spec. By default, the beans are not shared across JVMs. CDI will create one unique proxy per cluster member / jvm.

The part of Jakarta EE that is designed to handle this (by specification), is EJB.

like image 133
Hannes Schneidermayer Avatar answered Nov 07 '22 11:11

Hannes Schneidermayer


References to @ApplicationScoped are proxied, so they will be correctly resolved by the CDI container. That holds true no matter how many nodes are present within the application; the state and instance is shared across all client requests.

like image 1
Keith Avatar answered Nov 07 '22 09:11

Keith