Question

I have a set of worker threads where I run anonymous class runnables for long-running jobs. These threads last long after the response has been returned, but it seems that the thread that these Runnables were created on are still alive, and considered in use.

For implementation's sake, here is the code... in so many fewer words.

@Path("/myawesomeApp")
public class TheThing {
    static final TheWorkerPool pool = new TheWorkerPool();
    static final HashMap<Integer,String> map = new ConcurrentHashMap<Integer,String>();
    static int mapIdx = 0;

    @Context
    HttpServletContext context;

    @POST
    Integer doStuff() {
        Integer thisVariable = mapIdx++;     
        pool.enqueue(new Runnable() {
            public void run() {
                map.put(thisVariable, OtherStuff.dothings());
            }
        });
    }
}

Every one of them is stuck on the following:

  java.lang.Thread.State: RUNNABLE
    at org.apache.tomcat.jni.Socket.recvbb(Native Method)
    at org.apache.coyote.ajp.AjpAprProcessor.readt(AjpAprProcessor.java:1049)
    at org.apache.coyote.ajp.AjpAprProcessor.readMessage(AjpAprProcessor.java:1140)
    at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:368)
    at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:378)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
    at java.lang.Thread.run(Thread.java:619)
Was it helpful?

Solution

I guess TheThing's code is never called at all in this case. See AjpAprProcessor's source. It's stuck on reading some required http request's headers.

So check the ajp configuration and also ensure that client sends http requests correctly.

Try enabling logging on apache side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top