tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sumit Bhardwaj <sumit.bhard...@gmail.com>
Subject Issue with Async Servlet onTimeout
Date Wed, 27 Feb 2013 04:05:41 GMT
Hi,

I am using AsyncContext for implementing a file download app and seeing
issues on the timeout. I am using tomcat 7.0.23  (and have tried on 7.0.28
as well, but seeing the issue in 28 as well)

Here is the code snippet I use

*Servlet*

MyServelt{

......

final AsyncContext asyncContext = request.startAsync(request, response);

asyncContext.setTimeout(60000);

final DownloadChunkTask task = new DownloadChunkTask(asyncContext, input,
curRequestNo);

asyncContext.addListener(task);

....

}

*Async task*

MyTask{


 private final BufferedInputStream fileInputStream;

private final AsyncContext ctx;


MyTask(AsyncContext ctx,

  BufferedInputStream fileInputStream, long requestNo)

  throws IOException

{

this.ctx = ctx;

this.requestNo = requestNo;

this.fileInputStream = fileInputStream;

}


public void onComplete(AsyncEvent asyncEvent) throws IOException {

ctx.complete();

}


public void onTimeout(AsyncEvent asyncEvent) throws IOException {

LOG.warn("Asynchronous request timeout ({})", requestNo);

  onComplete(asyncEvent);

}


public Void call() throws Exception {

private final byte[] buffer = new byte[fileSize];

final int bytesCount = fileInputStream.read(buffer);

*ctx.getResponse().getOutputStream().write(buffer, 0, bytesCount);//The
threads are stuck here.*

}

 Is there any issue in the above code.


what I am facing is that the threads are stuck in the onCall method on the
write call whenever there is a timeout.


Regards,

Sumit

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message