Announcement Announcement Module
Collapse
No announcement yet.
Performance (Singleton/Prototype) getting beans indirectly via Web Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performance (Singleton/Prototype) getting beans indirectly via Web

    [Spring 2.0, Hibernate 3.1, Weblogic 8.5 - Workshop]

    Got my DAOs running in spring managed transactions both outside the container (via HibernateTransactionManager) and inside (via WebLogicJtaTransactionManager) by passing a SessionFactory to the DAOs. Works great.

    What about performance? Should the calls to my beans (via TransactionProxyFactoryBean) really be of type singleton?

    Right now I have created a Singleton Spring utility (see below) that loads the application context XML once and serves as the entry point for all bean calls in my Page Flow Controller (Workshop class created per web session/user). Each time I need a bean (which is a light weight facade over DAO objects) the Spring utility gets the bean which should be the only instance every created. What I am wondering is if the bean is unique for all Page Flow Controller instances (dvs. creating a bottleneck) or if every time a Controller is made as new Spring context is created thus building a new beans? Not clear? Let me know. Still trying to formulate the question in understandable english...

    Thanks in advance / matthew

  • #2
    I can't see the example that I think you meant to post.

    What I am wondering is if the bean is unique for all Page Flow Controller instances (dvs. creating a bottleneck) or if every time a Controller is made as new Spring context is created thus building a new beans?
    Assuming your bean is threadsafe, which it would normally be in this architectural role, you would want a single instance created ever and used in all your controller instances. Using a single instance will not create a bottleneck. If the object is naturally threadsafe it will not need synchronization, and any number of threads can pass through it simultaneously. Believe that a single instance poses a bottleneck is a common misconception.

    Comment


    • #3
      Alright (not too brushed up on concurrency with thread safe)

      Forgot to post the SpringUtil class:
      Code:
      package test.spring; 
      
      import org.springframework.context.ApplicationContext;
      import org.springframework.context.support.ClassPathXmlApplicationContext;
      
      public class SpringUtil 
      { 
          protected ApplicationContext mContext;
          protected static SpringUtil sInstance;
          
          protected SpringUtil() {
              mContext = new ClassPathXmlApplicationContext(
                  new String[] {
                      "applicationContext.xml"
                  }
              );            
          }
          
          public synchronized static SpringUtil getInstance() {
              if (sInstance == null) {
                  sInstance = new SpringUtil();
              }
              return sInstance;
          }
          
          public ApplicationContext getContext() {
              return mContext;
          }
      }
      Will have to read up on concurrency with thread safe objects. Does anybody have any good links/explanations or references in the documentation from either Spring or Hibernate? Want to get this techinically straight in my head.

      / matthew

      Comment

      Working...
      X