TaskExecuter threads keep running

I’ve been load testing a sample servoy application and I’ve been surprised by the number of TaskExecuter threads that are created. However, what concerns me most is that the threads don’t stop running after all night without any request to the server.

After last test, the server has been running all night and almost 60 TaskExecutor threads were running this morning.

Both web client and smart client behavior is similar and performing a profiling on the server I’ve notice that each thread is only active at the begining, but rest inactive since then.

I guess this is som kind of thread pool, but I wonder why inactive threads are reused.

This is the thread typical stack trace:

Name: TaskExecuter[54]
State: WAITING on com.servoy.j2db.util.TaskThreadPool$a@1ccadba
Total blocked: 79 Total waited: 872

Stack trace:
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:485)
com.servoy.j2db.util.am.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

Threads are extremely cheap on modern operating systems. Idle threads take very little resources, and operating systems easily support up to 1000s of threads.

A thread pool with 80 idle threads is really not an issue. The reason that inactive threads are reused is that you can’t reuse active threads (since they’re already being used), and for lots of small tasks it is inefficient to continually create new threads (a lot of overhead for a small piece of code).

Thanks for your answer sebster.

I had a mistake writting the question, I wonder why inactive threads are NOT reused, since most of them (if not all) only are active at the beginning of its life.

I know that 60 inactive threads is not a problem, but my concern is that, if threads are not reused and keep living, after a while we’ll have 10000s of inactive threads and this can indeed be a problem.

I guess that this won’t happen on Servoy, since I’ve seen Servoy servers running for months, however I just wanted to be sort of comforted by any of Servoy staff that this thread thing is under control :wink:

Ah, ok, don’t worry then. :-) They’re in a pool, and idle threads are not evicted but the pools have maximum sizes, so they’ll never grow to big.