Search code examples
spring-mvccontrollerloadtransactional

Heavy load on spring controller?


What happen even many request comes through one spring controller? Does Spring pipe it? How about add @Transactinal on controller? Is it have a benefit to use on controller layer?


Solution

  • Basically you are asking 2 questions

    1. How are multiple, concurrent, requests handled by a handler.
    2. Should we add @Transactional to a handler.

    Multiple concurrent requests are handled concurrently. Each thread has its own callstack and location in memory and doesn't share a thing. In general no problem (used Spring MVC in very high concurrent applications) unless you start, for some reason, sharing state in your singleton, or forget to clean-up ThreadLocals.

    Adding @Transactional is something bad, IMHO. The transactional layer is NOT your web but your service layer. So don't add transactions to your web but add them to your service layer.