Announcement Announcement Module
No announcement yet.
Safe Bean Publication Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • fixflyer
    started a topic Safe Bean Publication

    Safe Bean Publication

    Maybe the Spring community can clarify a thread safety question for me.

    I am fixing a stateful service-level bean that was wildly un-thread safe. Its members are accessed by no fewer than four different kinds of threads (and who knows how many actual threads).

    One of these thread 'groups' is the main, or initializing thread. This is the thread using Spring to instantiate and inject dependencies; logging indicates that the actual thread is 'main'.

    Another group is http-request threads managed by my servlet container, Tomcat.

    I understand that any state shared between these threads needs to be synchronized appropriately. But what ensures the safe publication of beans (and DispatcherServlet, etc) from the initializing thread to the http-request threads?

    In other words, how do I know that my bean creation and dependency injection 'happens-before' any (every) access to those beans by an http-request thread (I mean 'happens-before' in the strict JMM sense)?

    Is this the sole responsibility of the servlet container? If so, is this documented somewhere?

  • fixflyer
    This entry indicates that it is probably safe, but doesn't really have a definitive answer.

    This indicates documentation is coming in 3.0 (or 2.5.3?)

    Does anyone have a definitive answer?

    Leave a comment: