The current thread is dynamically managed by apache.
from worker.c in apache's source code:
thread is started as needed. following is the main flow to start worker thread.
static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
startup_children(remaining_children_to_start); //server/mpm/worker/worker.c
if (make_child(ap_server_conf, i) < 0) { //server/mpm/worker/worker.c
child_main(slot); //server/mpm/worker/worker.c
rv = apr_thread_create(&start_thread_id, thread_attr, start_threads
rv = apr_thread_create(&threads[i], thread_attr, worker_thread, my_info, pchild);
And when idle thread > max_spare_threads, apache will try to reduce the spare thread by kill child process/thread to reduce the idle threads count.
if (idle_thread_count > max_spare_threads) {
/* Kill off one child */
ap_worker_pod_signal(pod, TRUE);
retained->idle_spawn_rate = 1;
}
internally apache manage these child process, and using signal to communicate with child process to adjust threads as needed.
all threads are managed in ap_scoreboard_image->servers[i][j];
apache will monitor the thread count, and using socket send out to let infoCollector know.
roughly by following code (unrelated line were deleted)
./httpd/modules/cluster/mod_heartbeat.c
for (i = 0; i < ctx->server_limit; i++) {
....
for (j = 0; j < ctx->thread_limit; j++) {
ws = &ap_scoreboard_image->servers[i][j];
if (res == SERVER_READY && ps->generation == mpm_generation) {
ready++;
}
}
}
len = apr_snprintf(buf, sizeof(buf), "v=%u&ready=%u&busy=%u", MSG_VERSION, ready, busy);
...
rv = apr_socket_sendto(sock, ctx->mcast_addr, 0, buf, &len);
In Tomcat:
these thread info are received by:
./tomcat/java/org/apache/catalina/ha/backend/CollectedInfo.java
and displayed by:
/Users/twer/lab/tomcat/java/org/apache/catalina/manager/StatusTransformer.java
writer.write(" currentThreadCount=\"" + mBeanServer.getAttribute(tpName, "currentThreadCount") + "\"");
most of the code show here are main flow, unrelated line are deleted. download the source to find out more.
download apache src: http://www.apache.org/dist/httpd/?C=S;O=A
download tomcat src: http://tomcat.apache.org/download-70.cgi