You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Afkham Azeez <af...@gmail.com> on 2011/06/09 19:03:38 UTC

Terminating long running request threads

Hi folks,
We are using embedded Tomcat 7.0.14, and we have a requirement to somehow
terminate request threads that have been running for a 'long' time. Does
Tomcat provide any support to do this? Do we have access to the request
thread pool through JMX, and if so, is there a way to get hold of these long
running threads & terminate them?

Thanks
Azeez

Re: Terminating long running request threads

Posted by Afkham Azeez <af...@gmail.com>.
For our requirement, it is even OK to detect to which webapp such a request
is coming, and unload that webapp.


On Thu, Jun 9, 2011 at 10:33 PM, Afkham Azeez <af...@gmail.com> wrote:

> Hi folks,
> We are using embedded Tomcat 7.0.14, and we have a requirement to somehow
> terminate request threads that have been running for a 'long' time. Does
> Tomcat provide any support to do this? Do we have access to the request
> thread pool through JMX, and if so, is there a way to get hold of these long
> running threads & terminate them?
>
> Thanks
> Azeez
>

Re: Terminating long running request threads

Posted by Afkham Azeez <af...@gmail.com>.
Thanks! That Valve would be useful to achieve my purpose.

On Sun, Jun 12, 2011 at 12:19 AM, <sp...@gmx.eu> wrote:

> Have a look at this Valve:
>
>
> http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/catalina/valves
> /StuckThreadDetectionValve.java
>
> For Tomcat 7.0.14
>
> > -----Original Message-----
> > From: Afkham Azeez [mailto:afkham@gmail.com]
> > Sent: Samstag, 11. Juni 2011 19:23
> > To: Tomcat Users List
> > Subject: Re: Terminating long running request threads
> >
> > Thanks Rainer. I think I can use the RequestProcessor MBeans.
> >
> > Thanks
> > Azeez
> >
> > On Sat, Jun 11, 2011 at 8:41 PM, Rainer Jung
> > <ra...@kippdata.de>wrote:
> >
> > > On 11.06.2011 09:30, Afkham Azeez wrote:
> > > > Folks,
> > > > Is there any API to get hold of Tomcat's Connector thread pools?
> > >
> > > Each request is registered with an MBean in the MBeanServer.
> > > As long as the request is running, the MBean contains
> > additional info,
> > > like the URI, when the request started, the thread name etc.
> > >
> > > This gives you enough info to find long running requests
> > and to find the
> > > thread. But there's no non-deprecated Java API known to have no side
> > > effects to terminate a thread. If it were (or you find
> > one), we had to
> > > check how the thread pool behaves w.r.t. "vanishing" threads.
> > >
> > > Regards,
> > >
> > > Rainer
> > >
> > > > On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez
> > <af...@gmail.com> wrote:
> > > >
> > > >>
> > > >>
> > > >> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
> > > >> Chuck.Caldarale@unisys.com> wrote:
> > > >>
> > > >>>> From: Afkham Azeez [mailto:afkham@gmail.com]
> > > >>>> Subject: Terminating long running request threads
> > > >>>
> > > >>>> is there a way to get hold of these long running threads
> > > >>>> & terminate them?
> > > >>>
> > > >>> This is not an issue specific to Tomcat; there is no
> > way to safely
> > > >>> terminate a Java thread without the cooperation of that
> > thread.  Best
> > > if you
> > > >>> can code your webapp so that your request processors
> > periodically check
> > > if
> > > >>> they've been running too long and give up if so.
> > > >>>
> > > >>
> > > >> Yes, it is not a Tomcat specific issue. The thing is, we
> > don't have
> > > total
> > > >> control over what type of webapps will be deployed. We
> > do restrict
> > > certain
> > > >> operations using a Java Security Manager, but I do not
> > think we can
> > > restrict
> > > >> the running time of a Thread using a security manager. Using
> > > >> the ThreadMXBean we can monitor the time each thread
> > takes, and get the
> > > >> thread IDs of long running threads. It may be possible
> > to get that
> > > thread to
> > > >> terminate if we have some support for that from the
> > Tomcat threadpool.
> > > Just
> > > >> thinking out loud.
> > > >>
> > > >> Thanks
> > > >> Azeez
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > 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: Terminating long running request threads

Posted by sp...@gmx.eu.
Have a look at this Valve:

http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/catalina/valves
/StuckThreadDetectionValve.java

For Tomcat 7.0.14 

> -----Original Message-----
> From: Afkham Azeez [mailto:afkham@gmail.com] 
> Sent: Samstag, 11. Juni 2011 19:23
> To: Tomcat Users List
> Subject: Re: Terminating long running request threads
> 
> Thanks Rainer. I think I can use the RequestProcessor MBeans.
> 
> Thanks
> Azeez
> 
> On Sat, Jun 11, 2011 at 8:41 PM, Rainer Jung 
> <ra...@kippdata.de>wrote:
> 
> > On 11.06.2011 09:30, Afkham Azeez wrote:
> > > Folks,
> > > Is there any API to get hold of Tomcat's Connector thread pools?
> >
> > Each request is registered with an MBean in the MBeanServer.
> > As long as the request is running, the MBean contains 
> additional info,
> > like the URI, when the request started, the thread name etc.
> >
> > This gives you enough info to find long running requests 
> and to find the
> > thread. But there's no non-deprecated Java API known to have no side
> > effects to terminate a thread. If it were (or you find 
> one), we had to
> > check how the thread pool behaves w.r.t. "vanishing" threads.
> >
> > Regards,
> >
> > Rainer
> >
> > > On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez 
> <af...@gmail.com> wrote:
> > >
> > >>
> > >>
> > >> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
> > >> Chuck.Caldarale@unisys.com> wrote:
> > >>
> > >>>> From: Afkham Azeez [mailto:afkham@gmail.com]
> > >>>> Subject: Terminating long running request threads
> > >>>
> > >>>> is there a way to get hold of these long running threads
> > >>>> & terminate them?
> > >>>
> > >>> This is not an issue specific to Tomcat; there is no 
> way to safely
> > >>> terminate a Java thread without the cooperation of that 
> thread.  Best
> > if you
> > >>> can code your webapp so that your request processors 
> periodically check
> > if
> > >>> they've been running too long and give up if so.
> > >>>
> > >>
> > >> Yes, it is not a Tomcat specific issue. The thing is, we 
> don't have
> > total
> > >> control over what type of webapps will be deployed. We 
> do restrict
> > certain
> > >> operations using a Java Security Manager, but I do not 
> think we can
> > restrict
> > >> the running time of a Thread using a security manager. Using
> > >> the ThreadMXBean we can monitor the time each thread 
> takes, and get the
> > >> thread IDs of long running threads. It may be possible 
> to get that
> > thread to
> > >> terminate if we have some support for that from the 
> Tomcat threadpool.
> > Just
> > >> thinking out loud.
> > >>
> > >> Thanks
> > >> Azeez
> >
> >
> > 
> ---------------------------------------------------------------------
> > 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: Terminating long running request threads

Posted by Afkham Azeez <af...@gmail.com>.
Thanks Rainer. I think I can use the RequestProcessor MBeans.

Thanks
Azeez

On Sat, Jun 11, 2011 at 8:41 PM, Rainer Jung <ra...@kippdata.de>wrote:

> On 11.06.2011 09:30, Afkham Azeez wrote:
> > Folks,
> > Is there any API to get hold of Tomcat's Connector thread pools?
>
> Each request is registered with an MBean in the MBeanServer.
> As long as the request is running, the MBean contains additional info,
> like the URI, when the request started, the thread name etc.
>
> This gives you enough info to find long running requests and to find the
> thread. But there's no non-deprecated Java API known to have no side
> effects to terminate a thread. If it were (or you find one), we had to
> check how the thread pool behaves w.r.t. "vanishing" threads.
>
> Regards,
>
> Rainer
>
> > On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez <af...@gmail.com> wrote:
> >
> >>
> >>
> >> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
> >> Chuck.Caldarale@unisys.com> wrote:
> >>
> >>>> From: Afkham Azeez [mailto:afkham@gmail.com]
> >>>> Subject: Terminating long running request threads
> >>>
> >>>> is there a way to get hold of these long running threads
> >>>> & terminate them?
> >>>
> >>> This is not an issue specific to Tomcat; there is no way to safely
> >>> terminate a Java thread without the cooperation of that thread.  Best
> if you
> >>> can code your webapp so that your request processors periodically check
> if
> >>> they've been running too long and give up if so.
> >>>
> >>
> >> Yes, it is not a Tomcat specific issue. The thing is, we don't have
> total
> >> control over what type of webapps will be deployed. We do restrict
> certain
> >> operations using a Java Security Manager, but I do not think we can
> restrict
> >> the running time of a Thread using a security manager. Using
> >> the ThreadMXBean we can monitor the time each thread takes, and get the
> >> thread IDs of long running threads. It may be possible to get that
> thread to
> >> terminate if we have some support for that from the Tomcat threadpool.
> Just
> >> thinking out loud.
> >>
> >> Thanks
> >> Azeez
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Terminating long running request threads

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

Peter,

On 6/12/2011 5:49 AM, Peter Roßbach wrote:
> can we add the unique Thread Id, please?

If you can find the java.lang.Thread object, can't you get it's unique
id already? Maybe I'm misunderstanding your question.

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

iEYEARECAAYFAk32aXIACgkQ9CaO5/Lv0PCGpwCePJnyTL+6lC7jO2dkAe1uZL0j
YJ4AoIALl4DWko/V6MIbHzPTSNyHMksa
=84/7
-----END PGP SIGNATURE-----

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


Re: Terminating long running request threads

Posted by Peter Roßbach <pr...@objektpark.de>.
HI,

can we add the unique Thread Id, please?

Peter

Am 11.06.2011 um 17:11 schrieb Rainer Jung:

> On 11.06.2011 09:30, Afkham Azeez wrote:
>> Folks,
>> Is there any API to get hold of Tomcat's Connector thread pools?
> 
> Each request is registered with an MBean in the MBeanServer.
> As long as the request is running, the MBean contains additional info,
> like the URI, when the request started, the thread name etc.
> 
> This gives you enough info to find long running requests and to find the
> thread. But there's no non-deprecated Java API known to have no side
> effects to terminate a thread. If it were (or you find one), we had to
> check how the thread pool behaves w.r.t. "vanishing" threads.
> 
> Regards,
> 
> Rainer
> 
>> On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez <af...@gmail.com> wrote:
>> 
>>> 
>>> 
>>> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
>>> Chuck.Caldarale@unisys.com> wrote:
>>> 
>>>>> From: Afkham Azeez [mailto:afkham@gmail.com]
>>>>> Subject: Terminating long running request threads
>>>> 
>>>>> is there a way to get hold of these long running threads
>>>>> & terminate them?
>>>> 
>>>> This is not an issue specific to Tomcat; there is no way to safely
>>>> terminate a Java thread without the cooperation of that thread.  Best if you
>>>> can code your webapp so that your request processors periodically check if
>>>> they've been running too long and give up if so.
>>>> 
>>> 
>>> Yes, it is not a Tomcat specific issue. The thing is, we don't have total
>>> control over what type of webapps will be deployed. We do restrict certain
>>> operations using a Java Security Manager, but I do not think we can restrict
>>> the running time of a Thread using a security manager. Using
>>> the ThreadMXBean we can monitor the time each thread takes, and get the
>>> thread IDs of long running threads. It may be possible to get that thread to
>>> terminate if we have some support for that from the Tomcat threadpool. Just
>>> thinking out loud.
>>> 
>>> Thanks
>>> Azeez
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


Re: Terminating long running request threads

Posted by Rainer Jung <ra...@kippdata.de>.
On 11.06.2011 09:30, Afkham Azeez wrote:
> Folks,
> Is there any API to get hold of Tomcat's Connector thread pools?

Each request is registered with an MBean in the MBeanServer.
As long as the request is running, the MBean contains additional info,
like the URI, when the request started, the thread name etc.

This gives you enough info to find long running requests and to find the
thread. But there's no non-deprecated Java API known to have no side
effects to terminate a thread. If it were (or you find one), we had to
check how the thread pool behaves w.r.t. "vanishing" threads.

Regards,

Rainer

> On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez <af...@gmail.com> wrote:
> 
>>
>>
>> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
>> Chuck.Caldarale@unisys.com> wrote:
>>
>>>> From: Afkham Azeez [mailto:afkham@gmail.com]
>>>> Subject: Terminating long running request threads
>>>
>>>> is there a way to get hold of these long running threads
>>>> & terminate them?
>>>
>>> This is not an issue specific to Tomcat; there is no way to safely
>>> terminate a Java thread without the cooperation of that thread.  Best if you
>>> can code your webapp so that your request processors periodically check if
>>> they've been running too long and give up if so.
>>>
>>
>> Yes, it is not a Tomcat specific issue. The thing is, we don't have total
>> control over what type of webapps will be deployed. We do restrict certain
>> operations using a Java Security Manager, but I do not think we can restrict
>> the running time of a Thread using a security manager. Using
>> the ThreadMXBean we can monitor the time each thread takes, and get the
>> thread IDs of long running threads. It may be possible to get that thread to
>> terminate if we have some support for that from the Tomcat threadpool. Just
>> thinking out loud.
>>
>> Thanks
>> Azeez


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


Re: Terminating long running request threads

Posted by Afkham Azeez <af...@gmail.com>.
Folks,
Is there any API to get hold of Tomcat's Connector thread pools?

Regards
Azeez

On Thu, Jun 9, 2011 at 10:58 PM, Afkham Azeez <af...@gmail.com> wrote:

>
>
> On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
> Chuck.Caldarale@unisys.com> wrote:
>
>> > From: Afkham Azeez [mailto:afkham@gmail.com]
>> > Subject: Terminating long running request threads
>>
>> > is there a way to get hold of these long running threads
>> > & terminate them?
>>
>> This is not an issue specific to Tomcat; there is no way to safely
>> terminate a Java thread without the cooperation of that thread.  Best if you
>> can code your webapp so that your request processors periodically check if
>> they've been running too long and give up if so.
>>
>
> Yes, it is not a Tomcat specific issue. The thing is, we don't have total
> control over what type of webapps will be deployed. We do restrict certain
> operations using a Java Security Manager, but I do not think we can restrict
> the running time of a Thread using a security manager. Using
> the ThreadMXBean we can monitor the time each thread takes, and get the
> thread IDs of long running threads. It may be possible to get that thread to
> terminate if we have some support for that from the Tomcat threadpool. Just
> thinking out loud.
>
> Thanks
> Azeez
>

Re: Terminating long running request threads

Posted by Afkham Azeez <af...@gmail.com>.
On Thu, Jun 9, 2011 at 10:51 PM, Caldarale, Charles R <
Chuck.Caldarale@unisys.com> wrote:

> > From: Afkham Azeez [mailto:afkham@gmail.com]
> > Subject: Terminating long running request threads
>
> > is there a way to get hold of these long running threads
> > & terminate them?
>
> This is not an issue specific to Tomcat; there is no way to safely
> terminate a Java thread without the cooperation of that thread.  Best if you
> can code your webapp so that your request processors periodically check if
> they've been running too long and give up if so.
>

Yes, it is not a Tomcat specific issue. The thing is, we don't have total
control over what type of webapps will be deployed. We do restrict certain
operations using a Java Security Manager, but I do not think we can restrict
the running time of a Thread using a security manager. Using
the ThreadMXBean we can monitor the time each thread takes, and get the
thread IDs of long running threads. It may be possible to get that thread to
terminate if we have some support for that from the Tomcat threadpool. Just
thinking out loud.

Thanks
Azeez


>
>  - 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: Terminating long running request threads

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Afkham Azeez [mailto:afkham@gmail.com] 
> Subject: Terminating long running request threads

> is there a way to get hold of these long running threads
> & terminate them?

This is not an issue specific to Tomcat; there is no way to safely terminate a Java thread without the cooperation of that thread.  Best if you can code your webapp so that your request processors periodically check if they've been running too long and give up if so.

 - 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