I don’t know if this is why you see extra threads and might be unrelated, but note that the Temporal Java SDK uses threads in order to allow a workflow to have multiple call stacks at the same time – while only running one of those threads at a time because workflow execution is single threaded.
For example, consider a workflow which logs “before sleep”, then calls Workflow.sleep(), and then logs “after sleep”. At the point where it’s calling sleep, there’s a Java call stack so that after the sleep returns execution will continue with calling log “after sleep”. Meanwhile suppose there’s a signal handler that runs an activity, which runs while the first execution is paused in the sleep. The execution in the signal handler has its own call stack.
Some other languages have features like generators which you can use to get multiple call stacks, but in Java the only way to get multiple calls stacks is by using threads.
So again, I have no idea whether this might the source of the extra threads that you see or not, but in workflow executions at least, the multiple threads don’t consume CPU because only one thread is executing at a time.
java thread is not only memory resource, i would doubt that this is free, even memory can cause OOM. Is there any limitation for these threads or can i force sdk to use thread pools instead of creating huge amount of threads?
for workflow i found the way to setup workflowCacheSize >> maxWorkflowThreadCount(like workflowCacheSize=10000 maxWorkflowThreadCount=32), but it is against recommendation. Could anybody explain system behaviour for this case ?