Announcement Announcement Module
Collapse
No announcement yet.
Safe Bean Publication Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    replied
    This entry indicates that it is probably safe, but doesn't really have a definitive answer.

    http://weblogs.java.net/blog/tomwhit...r_beans_1.html

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

    http://jira.springframework.org/browse/SPR-4307

    Does anyone have a definitive answer?

    Leave a comment:

Working...
X