简体   繁体   中英

stateless singleton in Java EE

I want to define a "stateless singleton" in JAVA-EE which can be accessed by multiple threads simultanously.

By stateless I mean: the Bean-Instance has no fields.

Which one should I use:

version 1:

@javax.ejb.Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class MyStatelessSingleton {
..
}

version 2:

@ApplicationScoped
public class MyStatelessSingleton {
..
}

version 3:

@javax.inject.Singleton
public class MyStatelessSingleton {
..
}

By the way, I cannot see the benefit in having pooled "stateless instances" instead of one "stateless singleton bean".

I dont think that matters. Its a singleton. It stateless/statefull nature will be only dictated by how you implement it. ApplicationScoped is my favorite here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM