Results 1 to 4 of 4

Thread: application context - thread safe?

  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Default application context - thread safe?

    Are AbstractApplicationContext and it's descendants (File-, Classpath-) thread-safe? Can I use one instance to get beans from multiple threads? What's the strategy of using it in standalone multithreaded apps?

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Yes, the ApplicationContext descendants are thread-safe.

    When using the context in a stand-alone application you can use one of the BeanFactoryLocators or instantiate the ApplicationContext yourself (I suggest the former).

    Have a look at the BeanFactoryLocator JavaDoc and its subclasses.

    alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Apr 2008
    Posts
    1

    Default better clarification

    Hi Alef,

    After extensive googling on this topic, this was the only reference or assertion about spring's thread safety.

    Could please explain in more detail how Spring guarantees the thread safety of the application context?

    In particular, how does an application context guarantee that two threads cannot execute the same methods on the same bean at the same time?

    Thanks!

  4. #4
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Sorry, but you have completely mixed 2 concepts -
    thread safety of application context (which is just normal Java object with its own methods) and thread-safety of the beans created by the context as specified by configuration.

    Thread safety of application context means that methods of application context object may be concurrently called from many threads.
    It is achieved by design and coding of application context itself.

    Thread safety of the beans created by context - completely different matter,
    the only garantee that Spring gives is that bean is completely configured according to config info before is given out by context. Spring do not manage access to created beans in any way or attempts any synchronization efforts on them. It is completely up to you ensure that your beans are thread-safe.

    You may achive it by creating beans without mutable state (typical for DAOs and services) using non-shared beans (like prototype beans) or providing proper synchronization on your own.


    BTW, thread safety of the Spring was discussed many times in these forums as well as in many other forums, articles and blogs all over the Internet. I really do not understand why you have been unable to find links.

    Regards,
    Oleksandr

    Quote Originally Posted by slippy View Post
    Hi Alef,

    After extensive googling on this topic, this was the only reference or assertion about spring's thread safety.

    Could please explain in more detail how Spring guarantees the thread safety of the application context?

    In particular, how does an application context guarantee that two threads cannot execute the same methods on the same bean at the same time?

    Thanks!

Similar Threads

  1. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  2. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  3. Replies: 6
    Last Post: May 8th, 2005, 11:09 AM
  4. Sessions closing after commit
    By bendg25 in forum Data
    Replies: 0
    Last Post: Mar 21st, 2005, 04:38 AM
  5. Questioning the core component
    By Martin Kersten in forum Swing
    Replies: 6
    Last Post: Feb 21st, 2005, 03:45 AM

Posting Permissions

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