RE: [EXTERNAL] Re: Ensuring clean Tomcat shutdown

2020-06-08 Thread Amit Pande
Thank you Luis for the inputs.

Yes, we do use the listeners and  "contextDestroyed" and clean up the 
resources. But with many team members working, wanted to have some automated 
check to ensure cleaning up wasn't missed.


Thanks,
Amit

-Original Message-
From: Luis Rodríguez Fernández  
Sent: Monday, June 8, 2020 3:42 AM
To: Tomcat Users List 
Subject: [EXTERNAL] Re: Ensuring clean Tomcat shutdown

Hello Amit,

Well, your approach will work. Personally, I do not like very much to parse 
logs. We, for instance, in our tomcat instances we provide an application that 
queries the status of the deployed apps, see below.

If you have control in the code of  "AAA" application I would suggest you to 
implement contextDestroyed [1] and make a clean up of your resources (db 
connections, etc.)

The catalina stop  works beautifully in linux. I must to confess that it is 
being a while since I do not have a look at the catalina.bat one :)

Hope it helps,

Luis

[1]
https://tomcat.apache.org/tomcat-9.0-doc/servletapi/javax/servlet/ServletContextListener.html#contextDestroyed-javax.servlet.ServletContextEvent-

// From Registry javadocs: It provides methods to create and

// manipulate model mbeans and simplify their use.protected transient Registry 
registry;private static final String ALL_WEB_MODULES_QRY = 
"*:j2eeType=WebModule,*";

// Get all modules (contexts)
// Retrieve the MBean serverregistry = Registry.getRegistry(null, 
null);mBeanServer = Registry.getRegistry(null, 
null).getMBeanServer();Set objectNames = mBeanServer.queryNames(new 
ObjectName(ALL_WEB_MODULES_QRY), null);







El dom., 7 jun. 2020 a las 3:50, Amit Pande ()
escribió:

> When the application does not clean up the resources, during shutdown, 
> we see WARNINGs in Catalina logs:
>
> "WARNING [Catalina-utility-21]
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThread
> s The web application [AAA] appears to have started a thread named 
> [BBB] but has failed to stop it. This is very likely to create a 
> memory leak. Stack trace of thread:"
>
> I wanted to ensure a clean Tomcat shutdown and thinking of an 
> automated
> test:
>
>   1.  Stop Tomcat
>   2.  Parse/grep Catalina logs for warnings like above
>   3.  If found, fail the test, if not pass
>
> Is there a better/elegant way to achieve this? E.g. using life cycle 
> listeners?
>
> Also, the catalina stop  option (where a kill is attempted after n 
> seconds are passed) works for all platforms, is my understanding correct?
>
> Thanks,
> Amit
>


-- 

"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett


Re: Ensuring clean Tomcat shutdown

2020-06-08 Thread Luis Rodríguez Fernández
Hello Amit,

Well, your approach will work. Personally, I do not like very much to parse
logs. We, for instance, in our tomcat instances we provide an application
that queries the status of the deployed apps, see below.

If you have control in the code of  "AAA" application I would suggest you
to implement contextDestroyed [1] and make a clean up of your resources (db
connections, etc.)

The catalina stop  works beautifully in linux. I must to confess that it
is being a while since I do not have a look at the catalina.bat one :)

Hope it helps,

Luis

[1]
https://tomcat.apache.org/tomcat-9.0-doc/servletapi/javax/servlet/ServletContextListener.html#contextDestroyed-javax.servlet.ServletContextEvent-

// From Registry javadocs: It provides methods to create and

// manipulate model mbeans and simplify their use.protected transient
Registry registry;private static final String ALL_WEB_MODULES_QRY =
"*:j2eeType=WebModule,*";

// Get all modules (contexts)
// Retrieve the MBean serverregistry = Registry.getRegistry(null,
null);mBeanServer = Registry.getRegistry(null,
null).getMBeanServer();Set objectNames =
mBeanServer.queryNames(new ObjectName(ALL_WEB_MODULES_QRY), null);







El dom., 7 jun. 2020 a las 3:50, Amit Pande ()
escribió:

> When the application does not clean up the resources, during shutdown, we
> see WARNINGs in Catalina logs:
>
> "WARNING [Catalina-utility-21]
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The
> web application [AAA] appears to have started a thread named [BBB] but has
> failed to stop it. This is very likely to create a memory leak. Stack trace
> of thread:"
>
> I wanted to ensure a clean Tomcat shutdown and thinking of an automated
> test:
>
>   1.  Stop Tomcat
>   2.  Parse/grep Catalina logs for warnings like above
>   3.  If found, fail the test, if not pass
>
> Is there a better/elegant way to achieve this? E.g. using life cycle
> listeners?
>
> Also, the catalina stop  option (where a kill is attempted after n
> seconds are passed) works for all platforms, is my understanding correct?
>
> Thanks,
> Amit
>


-- 

"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett


Ensuring clean Tomcat shutdown

2020-06-06 Thread Amit Pande
When the application does not clean up the resources, during shutdown, we see 
WARNINGs in Catalina logs:

"WARNING [Catalina-utility-21] 
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web 
application [AAA] appears to have started a thread named [BBB] but has failed 
to stop it. This is very likely to create a memory leak. Stack trace of thread:"

I wanted to ensure a clean Tomcat shutdown and thinking of an automated test:

  1.  Stop Tomcat
  2.  Parse/grep Catalina logs for warnings like above
  3.  If found, fail the test, if not pass

Is there a better/elegant way to achieve this? E.g. using life cycle listeners?

Also, the catalina stop  option (where a kill is attempted after n seconds 
are passed) works for all platforms, is my understanding correct?

Thanks,
Amit