views:

29

answers:

0

We are using the ThreadPoolTaskExecutor within Spring (inside of Tomcat) to launch a concurrent server which listens on a port (3001).

Our code looks a bit like:

        ....
        ServerSocket listener = new ServerSocket(port);
        Socket server;

        while (true) {
            PollingTask pollingTask;

            server = listener.accept();
            log.info ("Got a new connection, spawning a thread: " + i++);
            taskExecutor.execute(new PollingTask(server, i));
        }

And the code for PollingTask is similar to:

   ....
   PollingTask(Socket server, int counter) {
        this.server = server;
        this.counter = counter;
    }

   public void run() {
        input = "";
        try {
            log.info ("New runnable thread: " + counter);
        }
   }
   ....

The Spring configuration looks like:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
   <property name="corePoolSize" value="100" />
   <property name="maxPoolSize" value="200" />
   <property name="queueCapacity" value="50" />
   <property name="keepAliveSeconds" value="600" />
</bean>

This particular bean is started on start up, and then we try to connect to the port (3001), using telnet.

Interestingly, we see, in our logs: Got a new connection, spawning a thread: 0 ....

However, it gets all the way to about 48 before it actually shows: New runnable thread: 0 ....

How do I convince Spring to work on the thread / task immediately, rather than waiting?

(I've tried with varying values for queueCapacity)