Results 1 to 3 of 3

Thread: Does Spring TransactionTemplate create threads?

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Default Does Spring TransactionTemplate create threads?

    I've got a problem with a corrupted data structure due to concurrent access. I'm trying to rule out possible causes, but I'm not sure how the Spring TransactionTemplate works.

    There are multiple threads passing independent lists to the constructor of a CallbackHandler. This CallbackHandler is then passed to the execute method of the TransactionTemplate. There are no synchronized blocks anywhere.

    The list is accessed in the CallbackHandler and from the calling Thread before and after the execute method has finished. As far as I understand calling execute DOESN'T start a new Thread. Therefor this should be safe.

    Every thread creates its own independent list and CallbackHandler, only the TransactionTemplate is the same for all.

    Or does Spring create some new thread at some point?

  2. #2
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

    In my opinion Spring does not create threads unless explicitly asked to. As far as transaction are concerned am pretty sure that Spring will not create new threads as context information required for a transaction will be lost at it is stored in thread local variables.

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Spring doesn't create new threads unless explicitly asked to do so. Next to that the TransactionTemplate, once constructed, is thread safe.

    Check your transaction settings and also be aware of the fact that a single transaction is bound to a thread, so if you expect all threads to participate in the SAME transaction that isn't going to work...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

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