1 Reply Latest reply on Mar 14, 2014 12:55 AM by ejb3workshop

    Multiple instances in @ApplicationScoped created

    ejb3workshop

      I created a bean and assigned it @ApplicationScoped in the hope it would behave like a singleton with a live span matching the entire application. However as it turns out on Tomcat using Weld 2.1.2 multiple instances of the bean are created. I was hoping on achieving a performance gain by caching items in the bean, but my attempts were thwarted as each instance obtain it's own sets of object, performing the expensive lookups multiple times. In one case I found 4-5 instances of a bean.

       

      Maybe I am miss-understanding what the @ApplicationScoped is. If it does create multiple instances, what are my option for creating a singleton bean which I can use to store expensive object in for later use.

       

      The other strange thing is that new instances are created all the time.

       

      I am using tomcat 7.0.50 with Weld 2.1.2.

       

      @Named(value = "optionBean")

      @ApplicationScoped

      @FacesConverter("funkyConverter")

      public class OptionBean extends AbstractBean implements Converter

      {

      ...

       

      Thanks for any information.