Hi,
On Thu, 12 Jul 2001 18:50, Endre St�lsvik wrote:
> How would you stop this thread?
>
> while(true);
something like this:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet
{
private Test test;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
String action = request.getParameter("action");
String output = null;
if ("start".equals(action))
{
if (test != null)
output = "thread already running.";
else
{
test = new Test();
test.start();
output = "starting thread.";
}
}
else if ("stop".equals(action))
{
if (test == null)
{
output = "thread doesn't exist.";
}
else
{
test.interrupt();
test = null;
output = "stopping thread.";
}
}
else
{
output = "unknown action.";
}
// this bit sets the content type
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(output);
}
private class Test extends Thread
{
public void run()
{
log("starting.");
int i=0;
while (true)
{
log("running " + (++i));
try
{
sleep(1000);
}
catch (InterruptedException ie)
{
log("interrupted.");
break;
}
if (isInterrupted())
{
log("exiting.");
break;
}
}
}
}
}
cheers
dim
- trapping session invalidation Pankaj Chhaparwal
- RE: trapping session invalidation Michael Wentzel
- RE: trapping session invalidation William Kaufman
- Killing endless loop servlet - howto ? killing ... Renato Weiner
- Re: Killing endless loop servlet - howto ? ... Dmitri Colebatch
- Re: Killing endless loop servlet - howt... Endre St�lsvik
- Re: Killing endless loop servlet -... Dmitri Colebatch
- Re: Killing endless loop servl... Endre St�lsvik
- Re: Killing endless loop s... Roland Carlsson
- Re: Killing endless loop s... Renato Weiner
- AW: Killing endless loop s... Dmitri Colebatch
- AW: Killing endless loop servlet -... Thorsten Schwarz
- Re: Killing endless loop servlet - howt... Renato Weiner
