---------------------------------------------------------------------------
HARBOR: http://coolharbor.100free.com/index.htm
Now Tomcat is also a cool pojo application server
---------------------------------------------------------------------------
----- Original Message -----
From: "christophe blin" <[EMAIL PROTECTED]>
Hi,
I'd like to cancel a servlet request if it took more than 5 seconds.
ATM, I know this is not possible directly via a tomcat configuration (in
fact I found no servlet container with this option).
By googling and doing a lot of tries (mainly based on
http://marc.info/?l=tomcat-user&m=109463824530983&w=2) , I find the
following snippet to be working but I have some problems with it.
1/ it use the deprecated Thread.stop method but I do not know if there is
a
way to use interrupt or any safer mecanism
2/ I do not know if this is really the best way to achieve what I want so
if
you have some pointers, do not hesitate to give them to me.
I dont like this at all.... if I read it right, its using a thread here as a
timer, and then killing the actual Tomcat thread... that cant be good.
So if tomcat needs to clean a buffer or do some house keeping, it cant... no
this can be good.
Have to ask why you cant just let the thread exit normally or let the
browser timeout, or let the user get bored and close the browser?
ie the scheme is pretty good already... ?
One way that would make sense to me is in the servlet proper... one creates
a background task, waits for the result, and then stops that.
ie you only messing with your own code... not bombing tomcats engine.
Never used it but SUN seems to have a FutureTask engine made for this sort
of thing.
I think other than messing with your own code... you cant.
This stuff below I think is trouble ;)
[code]
public class InterruptFilter implements Filter {
public void init(FilterConfig arg0) throws ServletException {
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain fc) throws IOException, ServletException {
InterruptTimer mTimer = new InterruptTimer(5000, 10,
Thread.currentThread());
mTimer.start();
fc.doFilter(request, response);
mTimer.reset();
}
public class InterruptTimer extends Thread {
long oEndTime = 0;
int oSleepTime = 10;
Thread oStartingThread = null;
public InterruptTimer(int aLength, int aSleepTime, Thread
aStartingThread) {
// Both times are in ms
oSleepTime = aSleepTime;
oEndTime = System.currentTimeMillis() + aLength;
oStartingThread = aStartingThread;
}
public void run() {
// Loop until the end time is reached or reset() was called.
while (System.currentTimeMillis() < oEndTime) {
try {
Thread.sleep(oSleepTime);
} catch (InterruptedException ex) {
}
}
if (oEndTime > 0) {
timeout();
}
}
public void reset() {
oEndTime = 0;
}
public void timeout() {
System.out.println("**************** stop the request thread");
oStartingThread.stop();
}
}
}
[/code]
--
View this message in context:
http://www.nabble.com/How-to-have-a-request-timeout---tf4855066.html#a13892897
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]