Announcement Announcement Module
Collapse
No announcement yet.
Performance Problems with ClassPathXmlApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performance Problems with ClassPathXmlApplicationContext

    I have a JSR-168 portlet that's been developed using portions of the Spring MVC Framework 2.0.8 and is being hosted in OC4J 10.1.3.3.0
    when under light load no problems are witnessed, however as load increases (using Grinder scripts), exceptions start getting thrown.
    These exceptions relate to Spring Context, which is being repeatedly during script execution from the Circumstances constructor. (Note that this does not happen on every call).
    It would appear that every time the Circumstances constructor is called, the context is invoked to access the property. I had expected that Spring would cache this after the first invocation. Is it possible to get Spring to cache this for subsequent invocations?

    Digging further, I have found that if I remove the namespace references from the <beans> element in resources-applicationContext.xml that this seems to make the problem disappear.

    Any suggestions would be much appreciated.

    Thanks in advance,
    Darran

    A typical stack trace is shown:
    Code:
    ERROR 2008-03-31 15:32:13 [HTTPThreadGroup-18] (SystemException.java:96) uk.gov.benefitsadviser.exceptions.SystemException - uk.gov.benefitsadviser.exceptions.SystemException: [gbnxv00101335618] [BAP-1000] An Unexpected Exception Occured.  See Causing Exception for more details 
    	at uk.gov.benefitsadviser.portlet.controllers.WelcomeController.formBackingObject(WelcomeController.java:145)
    	at org.springframework.web.portlet.mvc.AbstractFormController.getErrorsForNewForm(AbstractFormController.java:616)
    	at org.springframework.web.portlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:600)
    	at org.springframework.web.portlet.mvc.AbstractFormController.handleRenderRequestInternal(AbstractFormController.java:441)
    	at org.springframework.web.portlet.mvc.AbstractController.handleRenderRequest(AbstractController.java:223)
    	at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleRender(SimpleControllerHandlerAdapter.java:52)
    	at org.springframework.web.portlet.DispatcherPortlet.doRenderService(DispatcherPortlet.java:795)
    	at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:475)
    	at org.springframework.web.portlet.FrameworkPortlet.doDispatch(FrameworkPortlet.java:445)
    	at javax.portlet.GenericPortlet.render(GenericPortlet.java:163)
    	at oracle.portlet.server.containerimpl.ServerImpl.getMarkup(ServerImpl.java:161)
    	at oracle.portlet.wsrp.v1.WSRPv1ToServer.getMarkup(WSRPv1ToServer.java:4512)
    	at oracle.portlet.wsrp.v1.WSRP_v1_Markup_PortTypeSoapToJaxb.getMarkup(WSRP_v1_Markup_PortTypeSoapToJaxb.java:68)
    	at oasis.names.tc.wsrp.v1.bind.runtime.WSRP_v1_Markup_Binding_SOAP_Tie.invoke_getMarkup(WSRP_v1_Markup_Binding_SOAP_Tie.java:242)
    	at oasis.names.tc.wsrp.v1.bind.runtime.WSRP_v1_Markup_Binding_SOAP_Tie.processingHook(WSRP_v1_Markup_Binding_SOAP_Tie.java:785)
    	at oracle.j2ee.ws.server.StreamingHandler.handle(StreamingHandler.java:297)
    	at oracle.j2ee.ws.server.JAXRPCProcessor.doEndpointProcessing(JAXRPCProcessor.java:413)
    	at oracle.j2ee.ws.server.WebServiceProcessor.invokeEndpointImplementation(WebServiceProcessor.java:349)
    	at oracle.j2ee.ws.server.JAXRPCProcessor.doRequestProcessing(JAXRPCProcessor.java:277)
    	at oracle.j2ee.ws.server.WebServiceProcessor.processRequest(WebServiceProcessor.java:114)
    	at oracle.j2ee.ws.server.JAXRPCProcessor.doService(JAXRPCProcessor.java:134)
    	at oracle.j2ee.ws.server.WebServiceServlet.doPost(WebServiceServlet.java:177)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    	at oracle.portlet.server.service.ContextFilter.doFilter(ContextFilter.java:86)
    	at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
    	at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    	at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    	at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    	at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    	at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    	at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from class path resource [xml/resources-applicationContext.xml] is invalid; nested exception is oracle.xml.parser.schema.XSDException: invalid facet "enumeration" for type "simpleType"
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:369)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:394)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
    	at uk.gov.benefitsadviser.util.BenefitsAdviserContext.getContextObject(BenefitsAdviserContext.java:31)
    	at uk.gov.benefitsadviser.util.BenefitsAdviserContext.getContextObject(BenefitsAdviserContext.java:27)
    	at uk.gov.benefitsadviser.domain.Circumstances.<init>(Circumstances.java:55)
    	at uk.gov.benefitsadviser.domain.CurrentCircumstances.<init>(CurrentCircumstances.java:23)
    	at uk.gov.benefitsadviser.domain.Enquiry.<init>(Enquiry.java:39)
    	at sun.reflect.GeneratedConstructorAccessor50.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    	at java.lang.Class.newInstance0(Class.java:350)
    	at java.lang.Class.newInstance(Class.java:303)
    	at org.springframework.web.portlet.util.PortletUtils.getOrCreateSessionAttribute(PortletUtils.java:227)
    	at uk.gov.benefitsadviser.domain.logic.SessionStateHttpImpl.getOrCreateNewSession(SessionStateHttpImpl.java:51)
    	at uk.gov.benefitsadviser.portlet.controllers.WelcomeController.formBackingObject(WelcomeController.java:137)
    	... 35 more
    Caused by: oracle.xml.parser.schema.XSDException: invalid facet "enumeration" for type "simpleType"
    	at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:418)
    	at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:284)
    	at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:312)
    	at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:206)
    	at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:73)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:361)
    	... 60 more
    The relevant code fragments follow.
    Circumstances constructor:
    Code:
      public Circumstances() {
        logger.trace("Circumstances Constructer - start");
        // Set the max categories per questionPage property
        BenefitsAdviserProperties benefitsAdviserProperties = (BenefitsAdviserProperties) BenefitsAdviserContext.getContextObject("ba.BenefitsAdviserProperties");
        String maxCategoriesPerPageProperty = benefitsAdviserProperties.getProperty(MAX_CATEGORIES_PER_PAGE);
        if (maxCategoriesPerPageProperty == null) {
          throw new SystemException(ExceptionMessage.INVALID_PROPERTY_NAME, "Property with name [" + MAX_CATEGORIES_PER_PAGE + "] not found");
        } else {
          this.maxCategoriesPerPage = Integer.parseInt(maxCategoriesPerPageProperty);
        }
        logger.trace("Circumstances Constructer - end");
      }

    BenefitsAdviserContext:
    Code:
      public static Object getContextObject(String beanName){
         return getContextObject(beanName ,"xml/resources-applicationContext.xml");
      }
    continued in next post...

  • #2
    continued from previous post...

    resources-applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!--
      Resouce Definitions
    -->
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
      
      
      <!-- ========================= GENERAL DEFINITIONS ========================= -->
    
    
      
      <!-- ========================= BUSINESS OBJECT DEFINITIONS ======================== -->
      
      <bean id="ba.configObjectFactory" class="uk.gov.benefitsadviser.configuration.ConfigObjectFactory">
        <property name="benefitDefinitionResource" value="classpath:xml/Benefits.xml"/>
        <property name="categoryDefinitionResource" value="classpath:xml/QuestionCategory.xml"/>
        <property name="compositeQuestionResource" value="classpath:xml/CompositeQuestion.xml"/>
        <property name="questionDefinitionResource" value="classpath:xml/Questions.xml"/>
        <property name="rateDefinitionResource" value="classpath:xml/iBocRates.xml"/>
        <property name="extraRateDefinitionResource" value="classpath:xml/MyDwpRates.xml"/>
        <property name="textDefinitionResource" value="classpath:xml/Text.xml"/>
        <property name="rulesXsdDefinitionResource" value="classpath:xsd/BenefitsAdviserRequest.xsd"/>
        <property name="urlDefinitionResource" value="classpath:xml/Url.xml"/>
      </bean>
      
      <bean id="ba.BenefitsAdviserProperties" class="uk.gov.benefitsadviser.configuration.BenefitsAdviserProperties">
        <property name="benefitsAdviserProperties" value="classpath:properties/application.properties"/>
      </bean>
      
    </beans>

    Comment


    • #3
      And what does
      Code:
      getContextObject(beanName ,"xml/resources-applicationContext.xml");
      ?

      Does it instantiate new context each time? If so it is major design error.
      Context shall be instantiated once only - in Web-application preferrable as XmlWebApplicationContext via org.springframework.web.context.ContextLoader. Then you may use for example WebApplicationContextUtils.getWebApplicationContex t to access it.

      If for some reasons it is not suiteble for (while it is hard to imagine valid reasons) then create ClassPathXmlApplicationContext as static varible in one of your classes.

      Regards,
      Oleksandr

      Comment


      • #4
        Sorry - missed that method out:
        Code:
          public static Object getContextObject(String beanName, String location){
            ApplicationContext ctx = new ClassPathXmlApplicationContext(location);
            return ctx.getBean(beanName);
            
          }
        I'm new to Spring and still trying to get my head around it all. I appreciate the comments thus far - and will investigate moving it into web.xml

        Comment


        • #5
          So this method completely fullfil my expectations - you instantiate completely new context on each call of this method. Which is not only very expensive, but as well defeats the whole purpose of singletons as Spring singeltons are unique per container and per bean, see chapter 3.4.4.1 of Spring reference. As you instaniate each time new context (bean container) then you instantiate new copy of singletons (so they are singletons no more).

          The quickest fix is as follows:
          Code:
              private static final  ApplicationContext ctx = new new ClassPathXmlApplicationContext(location);
          
              public static Object getContextObject(String beanName, String location){
                   return ctx.getBean(beanName);    
              }

          And I strongly suggest to read at least chapters 1,3 and 4 of Spring Reference before any further development with Spring - this effort will pay for itself very promptly.

          Regards,
          Oleksandr

          Originally posted by dbames View Post
          Sorry - missed that method out:
          Code:
            public static Object getContextObject(String beanName, String location){
              ApplicationContext ctx = new ClassPathXmlApplicationContext(location);
              return ctx.getBean(beanName);
              
            }
          I'm new to Spring and still trying to get my head around it all. I appreciate the comments thus far - and will investigate moving it into web.xml

          Comment

          Working...
          X