Announcement Announcement Module
Collapse
No announcement yet.
New ApplicationContext instance per request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • New ApplicationContext instance per request

    Hi all,

    Are there any cons in creating a new ApplicaitonContext each time the application processes a request? The reason I want to do that is because the beans created (usually a service) contain state information that I want to keep (but not share across different requests due to threading issues) until the request is completed. I could make the bean a prototype but then I would have to managed the life cycle myself.

    Thanks,

    Vincent

  • #2
    This might get expensive. The ApplicationContext mechanism is not intended to be used like that (afaik). Therefore a significant performance degradation might be possible.

    I would advise to store just your state in a ThreadLocal.

    Regards,
    Andreas

    Comment


    • #3
      Thx for the reply, I think that's a nice solution but I have a question regarding the lifecycle of using a ThreadLocal bean: who's is control it? and would calling appCtx.getBean() return me the shared ThreadLocal object? I guess what I was looking for is something similar to HttpSession but since my application is not a web application, I have to find something else to replace it.

      Vincent

      Comment


      • #4
        Maybe org.springframework.aop.target.ThreadLocalTargetSo urce might be useful for you. I think it provides the functionality you need.

        Regards,
        Andreas

        Comment

        Working...
        X