开发者

Static Object in Jboss using EJB3

is it possible to create something like static object using EJB3 in Jboss. in other words i need to create something like a static object using singleton pattern or something like that, that is because i need to preload a configuration from database and i want that every bean that jboss creates uses th开发者_开发百科is class to read this configuration instead of that every bean load it from the database.

Cheers,


EJB 3.1 does have a standard @Singleton annotation but EJB 3.0 doesn't. However, JBoss offers a JBoss extension to the EJB 3.0 spec to create a singleton with the @Service annotation.

From the JBoss EJB 3.0 Reference Documentation:

Chapter 6. JBoss EJB 3.0 extensions

JBoss provides a few extensions to the EJB 3.0 spec. This chapter describes those features here.

6.1. @Service EJBs

An extension offered by JBoss EJB 3.0 is the notion of a @org.jboss.annotation.ejb.Service annotated bean. They are singleton beans and are not pooled, so only one instance of the bean exists in the server. They can have both @Remote and @Local interfaces so they can be accessed by java clients. When different clients look up the interfaces for @Service beans, all clients will work on the same instance of the bean on the server. When installing the bean it gets given a JMX ObjectName in the MBean server it runs on. The default is

jboss.j2ee:service=EJB3,name=<Fully qualified name of @Service bean>,type=service

You can override this default ObjectName by specifying the objectName attribute of the @Service annotation.

References

  • JBoss EJB 3.0 Reference Documentation
    • 6.1. @Service EJBs
  • JBoss EJB3 Tutorials
    • Chapter 28. Service POJOs (JBoss extension of EJB3)


Bean with @Singleton annotation should work. Place your database initialize code in @PostConstruct & can release/cleanup in @PreDestroy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜