Search code examples
javaspringmultithreadingpooling

Spring - Ensure Thread Pooling


The question is How to ensure that we can control how many concurrent calls there can be towards any given system from Spring application?

Secondary how to provide such functionality?

Does Spring already has such mechanism?

I have basic knowledge about FixedThreadPool but no clue how to implement such thing.

'Calls' as web service calls to external systems and subsystems. 'concurrent calls' - running at the same time - I don't know if that description helps.

Java/Spring based enterprise application - I'm new in project so I have huge lack of information yet.

What I've noticed till now it uses spring in version 4.x context, web, webmvc, core, aspects, aop, beans, orm, jdbc, context-support,


Solution

  • If you are using tomcat,In server.xml file you specify maxThreads which specifies maximum number of simultaneous requests that can be handled. Refer the documentation here.

    <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="4443" acceptCount="100"
                   debug="0" connectionTimeout="60000" 
                   disableUploadTimeout="true" />
    

    if you are using embeded tomcat (ie.Spring Boot), you can set the max threads as below.

    server.tomcat.max-threads = 300