You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Karthik Nanjangude <ka...@xius-bcgi.com> on 2010/08/03 13:06:47 UTC

Specific Thread of an web Application

Hi

O/s  : Redhat
JDK : 1.5
WebCont : Tomcat 6.0.20

Typical Problem:  How to kill a Specific Thread of an web Application on Tomcat?

Via Manually / JConsole





with regards

N.S.Karthik


Re: Specific Thread of an web Application

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Karthik,

On 8/3/2010 10:31 AM, Karthik Nanjangude wrote:
>>> application has some bad code built by a 3rd party
> 
> Yet another Problem ...
> we do not have the license to hack the code and fix the problem .... :(

You've been robbed.

> Any other Solutions please.

Hire someone else?

I don't believe JConsole allows you to interrupt threads in any way. You
can always write your own code to do it, though.

Let's just say for instance that your webapp had been written to
fire-off a thread for each user to do some stupid task and then leave
that thread in the user's session. You want to kill the thread when the
session dies. Here's one (unsafe) say to do it:

public class UserThreadMurderer
  implements HttpSessionListener
{
    public void sessionDestroyed(HttpSessionEvent evt)
    {
        HttpSession session = evt.getSession();

        if(null != session)
        {
            Thread userThread
                    = (Thread)session.getAttribute("dumb_thread");

            if(null != userThread)
            {
                if(ThreadState.TERMINATED == userThread.getState())
                {
                    // No need to stop the thread
                }
                else
                {
                   // ... and I'm all out of bubble gum

                   System.out.println("Murdering thread "
                          + userThread.getName()
                          + " which is terribly busy trying to:");

                   userThread.dumpStack();

                   try
                   {
                       // maybe try interrupt() first? nah...

/*
- From the Thread.stop javadoc:

[Use of Thread.stop] is inherently unsafe. Stopping a thread with
Thread.stop causes it to unlock all of the monitors that it has locked
(as a natural consequence of the unchecked ThreadDeath exception
propagating up the stack). If any of the objects previously protected by
these monitors were in an inconsistent state, the damaged objects become
visible to other threads, potentially resulting in arbitrary behavior.
Many uses of stop should be replaced by code that simply modifies some
variable to indicate that the target thread should stop running. The
target thread should check this variable regularly, and return from its
run method in an orderly fashion if the variable indicates that it is to
stop running. If the target thread waits for long periods (on a
condition variable, for example), the interrupt method should be used to
interrupt the wait. For more information, see Why are Thread.stop,
Thread.suspend and Thread.resume Deprecated?.
*/

                       userThread.stop(); // This is my "boom stick"
                   }
                   catch (Throwable t)
                   {
                       t.printStackTrace(); // probably should log this
                   }
                }
            }
        }
    }

    public void sessionCreated(HttpSessionEvent evt) { }
}

If you want even better code, you could always hire someone like me. Or
just me.

This really ought to be a last resort.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxYjCEACgkQ9CaO5/Lv0PCG1wCgplLtQcN724TqOam2WQfV/MDH
nIEAoIgOzDg1R7Kc6QYMcf2y/Bs2qNCI
=We6D
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Specific Thread of an web Application

Posted by Karthik Nanjangude <ka...@xius-bcgi.com>.
Hi

>> application has some bad code built by a
> 3rd party

Yet another Problem ...
we do not have the license to hack the code and fix the problem .... :(


Any other Solutions please.



With regards
karthik



-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
Sent: Tuesday, August 03, 2010 7:09 PM
To: Tomcat Users List
Subject: RE: Specific Thread of an web Application

> From: Karthik Nanjangude [mailto:karthik.nanjangude@xius-bcgi.com]
> Subject: RE: Specific Thread of an web Application
>
> I know that this particular application has some bad code built by a
> 3rd party.

Then you know the source of the problem, and will need to address it with them.  There is no safe way to terminate thread execution at an arbitrary point.  The code the thread is executing must be designed to be interrupted; no external tools are going to fix that.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Specific Thread of an web Application

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Karthik Nanjangude [mailto:karthik.nanjangude@xius-bcgi.com]
> Subject: RE: Specific Thread of an web Application
> 
> I know that this particular application has some bad code built by a
> 3rd party.

Then you know the source of the problem, and will need to address it with them.  There is no safe way to terminate thread execution at an arbitrary point.  The code the thread is executing must be designed to be interrupted; no external tools are going to fix that.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Specific Thread of an web Application

Posted by Mark Thomas <ma...@apache.org>.
On 03/08/2010 13:11, Karthik Nanjangude wrote:
> Hi
> 
> I know that this particular application has some bad code built by a 3rd party.
> 
>>> Potentially long running requests need to be coded to support being
> interrupted.
> 
> How this can be achieved from some tool like Jconsole ....

It can't.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Specific Thread of an web Application

Posted by Karthik Nanjangude <ka...@xius-bcgi.com>.
Hi

I know that this particular application has some bad code built by a 3rd party.

>> Potentially long running requests need to be coded to support being
interrupted.

How this can be achieved from some tool like Jconsole ....



With regards
karthik



-----Original Message-----
From: Mark Thomas [mailto:markt@apache.org]
Sent: Tuesday, August 03, 2010 5:32 PM
To: Tomcat Users List
Subject: Re: Specific Thread of an web Application

On 03/08/2010 12:43, Karthik Nanjangude wrote:
> Hi
>
> Can this specific thread be killed by expiration of session from Sessions Administration of manage screen

No. Generally, killing threads isn't safe and is asking for a JVM crash.
Potentially long running requests need to be coded to support being
interrupted.

Mark

>
>
> with regards
> Karthik
>
>
>
>
> -----Original Message-----
> From: Pid [mailto:pid@pidster.com]
> Sent: Tuesday, August 03, 2010 4:42 PM
> To: Tomcat Users List
> Subject: Re: Specific Thread of an web Application
>
> On 03/08/2010 12:06, Karthik Nanjangude wrote:
>> Hi
>>
>> O/s  : Redhat
>> JDK : 1.5
>> WebCont : Tomcat 6.0.20
>>
>> Typical Problem:  How to kill a Specific Thread of an web Application on Tomcat?
>>
>> Via Manually / JConsole
>
> Call Thread.interrupt() or with much more risk Thread.stop(), or is this
> not what you mean?
>
>
> p
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Specific Thread of an web Application

Posted by Mark Thomas <ma...@apache.org>.
On 03/08/2010 12:43, Karthik Nanjangude wrote:
> Hi
> 
> Can this specific thread be killed by expiration of session from Sessions Administration of manage screen

No. Generally, killing threads isn't safe and is asking for a JVM crash.
Potentially long running requests need to be coded to support being
interrupted.

Mark

> 
> 
> with regards
> Karthik
> 
> 
> 
> 
> -----Original Message-----
> From: Pid [mailto:pid@pidster.com]
> Sent: Tuesday, August 03, 2010 4:42 PM
> To: Tomcat Users List
> Subject: Re: Specific Thread of an web Application
> 
> On 03/08/2010 12:06, Karthik Nanjangude wrote:
>> Hi
>>
>> O/s  : Redhat
>> JDK : 1.5
>> WebCont : Tomcat 6.0.20
>>
>> Typical Problem:  How to kill a Specific Thread of an web Application on Tomcat?
>>
>> Via Manually / JConsole
> 
> Call Thread.interrupt() or with much more risk Thread.stop(), or is this
> not what you mean?
> 
> 
> p
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Specific Thread of an web Application

Posted by Karthik Nanjangude <ka...@xius-bcgi.com>.
Hi

Can this specific thread be killed by expiration of session from Sessions Administration of manage screen


with regards
Karthik




-----Original Message-----
From: Pid [mailto:pid@pidster.com]
Sent: Tuesday, August 03, 2010 4:42 PM
To: Tomcat Users List
Subject: Re: Specific Thread of an web Application

On 03/08/2010 12:06, Karthik Nanjangude wrote:
> Hi
>
> O/s  : Redhat
> JDK : 1.5
> WebCont : Tomcat 6.0.20
>
> Typical Problem:  How to kill a Specific Thread of an web Application on Tomcat?
>
> Via Manually / JConsole

Call Thread.interrupt() or with much more risk Thread.stop(), or is this
not what you mean?


p


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Specific Thread of an web Application

Posted by Pid <pi...@pidster.com>.
On 03/08/2010 12:06, Karthik Nanjangude wrote:
> Hi
> 
> O/s  : Redhat
> JDK : 1.5
> WebCont : Tomcat 6.0.20
> 
> Typical Problem:  How to kill a Specific Thread of an web Application on Tomcat?
> 
> Via Manually / JConsole

Call Thread.interrupt() or with much more risk Thread.stop(), or is this
not what you mean?


p