Results 1 to 4 of 4

Thread: New ApplicationContext instance per request

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  3. #3
    Join Date
    Jul 2005
    Posts
    3

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

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

    Regards,
    Andreas

Similar Threads

  1. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  4. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  5. DefaultAdvisorAutoProxyCreator skipping beans
    By youngm in forum Container
    Replies: 6
    Last Post: Apr 12th, 2005, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •