Announcement Announcement Module
Collapse
No announcement yet.
one thread per managed bean? or per container? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • one thread per managed bean? or per container?

    hi,

    does spring assign a thread for every managed component/bean by default?
    or could it be configured to do so?
    what about thread-safety in this case?

    it seems like a fundamental question but i cannot find anything in the introductory material.


    any hint is appreciated
    thanks
    matthias

  • #2
    AFAIK, Spring has nothing to do with threads, per se. There is no separate container thread either.

    Comment


    • #3
      Usually the J2EE container manages the thread. And Spring objects operate in that same thread. So for an EJB (where the thread is created by the container) it looks up the Spring object and executes its method in the same thread. Same for operations during a web request.

      As for thread safety: This depends on your design. For data access components, they tend to be thread safe, so you only need one. But if for some reason you can't, then you might use a non-singleton object and create one per thread.

      Comment


      • #4
        spring as only container - thread management again

        Originally posted by wpoitras
        Usually the J2EE container manages the thread. And Spring objects operate in that same thread. So for an EJB (where the thread is created by the container) it looks up the Spring object and executes its method in the same thread. Same for operations during a web request.

        As for thread safety: This depends on your design. For data access components, they tend to be thread safe, so you only need one. But if for some reason you can't, then you might use a non-singleton object and create one per thread.
        thanks for the reply. in the case i am considering spring would be my only 'appserver'/container. my components would be plain pojo beans. but i still want them to live in their own thread each. does that mean i am out of luck and have to do the thread management manually?
        from what i had read about spring i got the impression that it was well intended to be used as a light-weight stand-alone pojo container.
        so any suggestion for thread management (which excludes an implementation from scratch) would be appreciated

        thanks
        matthias

        Comment


        • #5
          You should look at the java.util.concurrent package in Java 1.5.
          There is a backport of this to Java 1.4 at http://www.mathcs.emory.edu/dcl/util...il-concurrent/

          Comment

          Working...
          X