[prev in list] [next in list] [prev in thread] [next in thread]
List: tomcat-user
Subject: Non-blocking IO Question
From: Daniel Mikusa <dmikusa () gopivotal ! com>
Date: 2013-11-25 0:20:17
Message-ID: FD8FC452-84DC-4D05-BF00-4A5AB65FA457 () gopivotal ! com
[Download RAW message or body]
I have a question on usage with non-blocking IO. I'm setting up a ReadListener which \
implements onDataAvailable like this...
@Override
public void onDataAvailable() throws IOException
{
while (input.isReady())
{
int read = input.read(buffer);
// do something with data...
}
// if we're done reading, close up
if (input.isFinished())
{
complete = true;
asyncContext.complete();
}
}
This seems to be working, but I'm getting the following NullPointerException.
SEVERE: Exception while processing an asynchronous request
java.lang.NullPointerException
at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:389)
at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1618)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:631)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1555)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
After debugging a bit, here is what seems to be happening…
1.) Tomcat calls "onDataAvailable".
2.) The method above runs and reads all of the data. Because all the data is \
processed, it comples the context. 3.) Tomcat now tries to call "onAllDataRead", but \
I think because I've closed the context it fails.
For reference, here's the section of code from CoyoteAdapter where the NPE is \
generated.
Thread.currentThread().setContextClassLoader(newCL);
req.getReadListener().onDataAvailable();
if (request.isFinished()) {
req.getReadListener().onAllDataRead(); // <-- NPE thrown \
here }
My question here, is my code wrong to call asyncContext.complete() like this? If I \
restructure it to wait for "onAllDataRead" and complete the context from there then \
everything works OK.
Thanks
Dan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic