Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Dmitri Colebatch

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




Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Renato Weiner
 Can we register the running thread in the service() method of the ServletWrapper object and then call a thread.interrupt() in the servlet.destroy method ? So we could stop the thread where unloading the context. Should this do the work ? 
  Roland Carlsson <[EMAIL PROTECTED]> wrote: 
- Original Message - From: "Endre Stølsvik" <[EMAIL PROTECTED]>To: <[EMAIL PROTECTED]>Sent: Thursday, July 12, 2001 10:50 AMSubject: Re: Killing endless loop servlet - howto ? killing JVM or unload class ?> On Thu, 12 Jul 2001, Dmitri Colebatch wrote:> > | On Thu, 12 Jul 2001 16:28, you wrote:> | > I thought the problem with threads was that you actually _cannot_ kill> | > them, even "in Java". I find this stupid, and hope I'm wrong! But> | > apparently you can only "ask" the thread to interrupt and check for status> | > by using the thread.interrupt(), and isInterrupted() inside the thread.> | The purpose of this is to force a two-phase termination, and give the thread> | a chance to clean up... its up to the thread programmer to be aware of any> | requests for interruption. When you say you can only "ask", you are correct.> | I dont see why this prohibits my earlier suggestion though...> > How would you stop this thread?> > while(true);> > > -- > Mvh,> Endre> Hi!public booelan running;public void run(){while(running){}}Another thread can then stop the thread by altering running to false. Then the thread will have the possibility to clean after itself.You must ofcourse register the tread somewhere so you can find it but that is another question. Perhpas something to implement at serverlevel so a admin can look for running threads and kill them off...RegardsRoland CarlssonDo You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!http://personal.mail.yahoo.com/

Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Renato Weiner
Hi,
Actually I'm testing some time-out features of Tomcat. Users eventually ended up doing endless loops ( like, forgetting to move to next line in a database record set... ). So, what I'm trying to see if there is a patch that could kill the 'offending' threads after a defined time interval.
Thanks
Renato.
 
 
  Dmitri Colebatch <[EMAIL PROTECTED]> wrote: 
Does it intentionally loop forever? If so, creating a new thread and having that do the work (hence returning tomcat's thread to the server) should do the trick.cheersdimOn Sat, 30 Jun 2001 07:28, you wrote:> Hi all,> I'm rolling out a successful Tomcat instalation in a shared environment (> it's a great software ! ). But I have a concern. I created a servlet that> loops forever ( a very stupid one, by the way ). When I executed it, it> allocates a Tomcat thread and it just runs forever. If I try to kill it> after it consumed, let's say, 30 seconds of processing, it ended up killing> the whole JVM. First, I don't know if it's killing a thread is the right> approach. Should I do that, without shutdown Tomcat ? Is there a way to set> a 'time-out' for a Servlet ? What I can do in this situation ? Is there an> Interceptor that can unload this class somehow ? Thanks in advance> Renato - Brazil> P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2 -> Do You Yahoo!?> Get personalized email addresses from Yahoo! Mail - only $35 a year!> http://personal.mail.yahoo.com/Content-Type: text/html; charset="us-ascii"; name="Attachment: 1"Content-Transfer-Encoding: 7bitContent-Description: Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!http://personal.mail.yahoo.com/

Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Roland Carlsson


- Original Message - 
From: "Endre Stølsvik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 12, 2001 10:50 AM
Subject: Re: Killing endless loop servlet - howto ? killing JVM or unload class ?


> On Thu, 12 Jul 2001, Dmitri Colebatch wrote:
> 
> | On Thu, 12 Jul 2001 16:28, you wrote:
> | > I thought the problem with threads was that you actually _cannot_ kill
> | > them, even "in Java". I find this stupid, and hope I'm wrong! But
> | > apparently you can only "ask" the thread to interrupt and check for status
> | > by using the thread.interrupt(), and isInterrupted() inside the thread.
> | The purpose of this is to force a two-phase termination, and give the thread
> | a chance to clean up... its up to the thread programmer to be aware of any
> | requests for interruption.  When you say you can only "ask", you are correct.
> |  I dont see why this prohibits my earlier suggestion though...
> 
> How would you stop this thread?
> 
> while(true);
> 
> 
> -- 
> Mvh,
> Endre
> 

Hi!

public booelan running;


public void run(){
while(running){
}
}

Another thread can then stop the thread by altering running to false. Then the thread 
will have the possibility to clean after itself.

You must ofcourse register the tread somewhere so you can find it but that is another 
question. Perhpas something to implement at serverlevel so a admin can look for 
running threads and kill them off...

Regards
Roland Carlsson






AW: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Thorsten Schwarz



> I thought the problem with threads was that you actually _cannot_ kill
> them, even "in Java". I find this stupid, and hope I'm wrong! But

That's the point. There is NO WAY in a JVM to stop or kill an arbitrary
thread from outside. This is one of the main disadvantages in Java!!
Even unloading the class by garbage collecting the classloader that loaded
the running thread class wouldn't help because the running class is only
garbage collected if its in no use by any thread (in this case by itself).


Thorsten




Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-12 Thread Dmitri Colebatch

On Thu, 12 Jul 2001 16:28, you wrote:
> I thought the problem with threads was that you actually _cannot_ kill
> them, even "in Java". I find this stupid, and hope I'm wrong! But
> apparently you can only "ask" the thread to interrupt and check for status
> by using the thread.interrupt(), and isInterrupted() inside the thread.
The purpose of this is to force a two-phase termination, and give the thread 
a chance to clean up... its up to the thread programmer to be aware of any 
requests for interruption.  When you say you can only "ask", you are correct. 
 I dont see why this prohibits my earlier suggestion though...

cheers
dim




Re: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-11 Thread Dmitri Colebatch

Does it intentionally loop forever?  If so, creating a new thread and having 
that do the work (hence returning tomcat's thread to the server) should do 
the trick.

cheers
dim


On Sat, 30 Jun 2001 07:28, you wrote:
>  Hi all,
> I'm rolling out a successful Tomcat instalation in a shared environment (
> it's a great software ! ). But I have a concern. I created a servlet that
> loops forever ( a very stupid one, by the way ). When I executed it, it
> allocates a Tomcat thread and it just runs forever. If I try to kill it
> after it consumed, let's say, 30 seconds of processing, it ended up killing
> the whole JVM. First, I don't know if it's killing a thread is the right
> approach. Should I do that, without shutdown Tomcat ? Is there a way to set
> a 'time-out' for a Servlet ? What I can do in this situation ? Is there an
> Interceptor that can unload this class somehow ? Thanks in advance
> Renato - Brazil
> P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2
>
>
>
> -
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35 a year!
> http://personal.mail.yahoo.com/


Content-Type: text/html; charset="us-ascii"; name="Attachment: 1"
Content-Transfer-Encoding: 7bit
Content-Description: 




Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-11 Thread Renato Weiner
 Hi all,
I'm rolling out a successful Tomcat instalation in a shared environment ( it's a great software ! ). But I have a concern. 
I created a servlet that loops forever ( a very stupid one, by the way ). When I executed it, it allocates a Tomcat thread and it just runs forever. If I try to kill it after it consumed, let's say, 30 seconds of processing, it ended up killing the whole JVM. 
First, I don't know if it's killing a thread is the right approach. Should I do that, without shutdown Tomcat ? Is there a way to set a 'time-out' for a Servlet ? What I can do in this situation ? Is there an Interceptor that can unload this class somehow ?
Thanks in advance 
Renato - Brazil
P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!http://personal.mail.yahoo.com/

RE: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-02 Thread JBrawner


> First, I don't know if it's killing a thread is the right approach.
Should
I do that, without shutdown Tomcat ?

If you must have an endless loop, here is a way to kill it.

try
{
   while (true)
   {
 // inside infinite loop
   }
}
catch (InterruptedException)
{
}

When you want the thread to be killed, just call it's interrupt() method.
This will catch the exception outside the loop and terminate.

Just a suggestion...

Jason E. Brawner
Silenus Group



   

William

Kaufman  To: "'[EMAIL PROTECTED]'"

  

uity.com>cc:   

 Subject: RE: Killing endless loop servlet 
- howto ? killing JVM or
07/02/2001   unload   class ?  

10:11 AM   

Please 

respond to 

tomcat-user

   

   





OK, no one's answered this yet, so,...

> First, I don't know if it's killing a thread is the right approach.
Should
I do that, without shutdown Tomcat ?

So, why are you creating an infinite loop?  I mean, if you didn't, you
wouldn't have to kill it.

If you're generally asking how one can kill threads in Java, you could use
java.lang.Thread.stop() (but read the deprecation warning).  But as a rule,
not creating infinite loops is a much better strategy.

> Is there a way to set a 'time-out' for a Servlet ?

Not the way you mean.  You can set a timeout for a session (by modifying
your web.xml); but AFAIK, the only way to set a timeout for a request would
be on your browser.

-- Bill K.

-Original Message-
From: Renato Weiner [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 02, 2001 6:03 AM
To: [EMAIL PROTECTED]
Subject: Killing endless loop servlet - howto ? killing JVM or unload class
?


Hi all,
I'm rolling out a successful Tomcat instalation in a shared environment (
it's a great software ! ). But I have a concern.
I created a servlet that loops forever ( a very stupid one, by the way ).
When I executed it, it allocates a Tomcat thread and it just runs forever.
If I try to kill it after it consumed, let's say, 30 seconds of processing,
it ended up killing the whole JVM.
First, I don't know if it's killing a thread is the right approach. Should
I
do that, without shutdown Tomcat ? Is there a way to set a 'time-out' for a
Servlet ? What I can doin this situation ? Is there an Interceptor that can
unload this class somehow ?
Thanks in advance
Renato - Brazil
P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2




Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 a year!
http://personal.mail.yahoo.com/







RE: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-02 Thread Renato Weiner
> OK, no one's answered this yet, so,...>> First, I don't know if it's killing a thread is the right approach. Should I do that, without shutdown Tomcat ? > So, why are you creating an infinite loop? I mean, if you didn't, you wouldn't have to kill it.
The problem is my environment. Since this is a webhosting, I cannot control what my users do. I'm 100% sure that they will create code that will run forever. I need to find a way to avoid this.> If you're generally asking how one can kill threads in Java, you could use java.lang.Thread.stop() (but read the deprecation warning). But as a rule, not creating infinite loops is a much better strategy.>> Is there a way to set a 'time-out' for a Servlet ?> Not the way you mean. You can set a timeout for a session (by modifying your web.xml); but AFAIK, the only way to set a timeout for a request would be on your browser.What about a patch for PoolTcpConnector ? Anyone ?
Thanks !-Original Message-From: Renato Weiner [mailto:[EMAIL PROTECTED]]Sent: Monday, July 02, 2001 6:03 AMTo: [EMAIL PROTECTED]Subject: Killing endless loop servlet - howto ? killing JVM or unload class?Hi all, I'm rolling out a successful Tomcat instalation in a shared environment (it's a great software ! ). But I have a concern. I created a servlet that loops forever ( a very stupid one, by the way ).When I executed it, it allocates a Tomcat thread and it just runs forever.If I try to kill it after it consumed, let's say, 30 seconds of processing,it ended up killing the whole JVM. First, I don't know if it's killing a thread is the right approach. Should Ido that, without shutdown Tomcat ? Is there a way to set a 'time-out' for aServlet ? What I can doin this situation ? Is there an Interceptor that canunload this class somehow ? Thanks in advance Renato - Brazil P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2Do You Yahoo!?Get personalized email addresses from Yahoo! Mail - only $35 a year!http://personal.mail.yahoo.com/Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!http://personal.mail.yahoo.com/

RE: Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-02 Thread William Kaufman

OK, no one's answered this yet, so,...

> First, I don't know if it's killing a thread is the right approach. Should
I do that, without shutdown Tomcat ? 

So, why are you creating an infinite loop?  I mean, if you didn't, you
wouldn't have to kill it.

If you're generally asking how one can kill threads in Java, you could use
java.lang.Thread.stop() (but read the deprecation warning).  But as a rule,
not creating infinite loops is a much better strategy.

> Is there a way to set a 'time-out' for a Servlet ?

Not the way you mean.  You can set a timeout for a session (by modifying
your web.xml); but AFAIK, the only way to set a timeout for a request would
be on your browser.

-- Bill K. 

-Original Message-
From: Renato Weiner [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 02, 2001 6:03 AM
To: [EMAIL PROTECTED]
Subject: Killing endless loop servlet - howto ? killing JVM or unload class
?


Hi all, 
I'm rolling out a successful Tomcat instalation in a shared environment (
it's a great software ! ). But I have a concern. 
I created a servlet that loops forever ( a very stupid one, by the way ).
When I executed it, it allocates a Tomcat thread and it just runs forever.
If I try to kill it after it consumed, let's say, 30 seconds of processing,
it ended up killing the whole JVM. 
First, I don't know if it's killing a thread is the right approach. Should I
do that, without shutdown Tomcat ? Is there a way to set a 'time-out' for a
Servlet ? What I can doin this situation ? Is there an Interceptor that can
unload this class somehow ? 
Thanks in advance 
Renato - Brazil 
P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2




Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 a year!
http://personal.mail.yahoo.com/



Killing endless loop servlet - howto ? killing JVM or unload class ?

2001-07-02 Thread Renato Weiner
Hi all, 
I'm rolling out a successful Tomcat instalation in a shared environment ( it's a great software ! ). But I have a concern. 
I created a servlet that loops forever ( a very stupid one, by the way ). When I executed it, it allocates a Tomcat thread and it just runs forever. If I try to kill it after it consumed, let's say, 30 seconds of processing, it ended up killing the whole JVM. 
First, I don't know if it's killing a thread is the right approach. Should I do that, without shutdown Tomcat ? Is there a way to set a 'time-out' for a Servlet ? What I can doin this situation ? Is there an Interceptor that can unload this class somehow ? 
Thanks in advance 
Renato - Brazil 
P.S. I'm running Linux, kernel 2.4.3, Tomcat 3.2.2Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!http://personal.mail.yahoo.com/