-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Shawn,

On 3/27/18 10:26 PM, Shawn Heisey wrote:
> This is what the code in our application looks like that gets a 
> datasource object from the context:
> 
> Context initContext = new InitialContext(); Context envContext  =
> (Context)initContext.lookup("java:/comp/env"); DataSource ds =
> (DataSource)envContext.lookup("jdbc/REDACTED");
> 
> I would like to write a logging thread that can get ALL of the 
> datasource objects from the context, and for types that it knows,
> cast them to the appropriate object to log the active/idle
> connection counts.

It might be easier to do this via JMX.

> This paste is the idea I've thought of for initializing and
> creating this logging thread:
> 
> https://paste.apache.org/QcbE
> 
> The "log" variable is an slf4j Logger object.
> 
> Does that code look like it'll work, if we run it once at system 
> startup?  It doesn't have any errors in my IDE.  Which is not
> always an indication of success!

Since you already have a compile-time dependency upon Tomcat, there's
no need to do class-name matching. Instead, just use "instanceof" as
before:

DataSource ds = myMap.get(dsName);
if(ds instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource)
{
  (cast)
  (log)
}

Instead of running a single thread that goes to sleep, maybe consider
using a ScheduledExecutorService with a simpler runnable object that
just logs the status a single time.

Don't forget to terminate the thread (or ExecutorService) when the
application is shutting-down, of you'll have a ClassLoader (and a a
huge memory) leak.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlq76pYACgkQHPApP6U8
pFixAw//Ue6UyyLh+y59CEFalOrW0credrwh+i986CYL52wujdmgqmRts1o86N1s
UcSQ3dF4dp6VwZpaiZYrl2dJoxsk6alSkxGJ8zFQ4BsTps5fCehcWdBBf/iWT+Bz
/vbTqo/5o6g8/Sz8GqZ6AUD0gzU1TxIqqy30v5+7hClYLHVR0jZdTlWlX4bq8o44
OKC5imdV2jSCzJeq864BJNSA6/Ttcxsp4OrWZiHMc4YlW6tz7O8jqeB4t4wO+E8f
SoIla76A1L8dajtw85E1PPGFsD4pyBKrcMW9RIlt/ZqoQyI5UbDwOjN4MFBi6AnI
TSwj5fXcjLuFDoXwiZJo8Pvc6fLEc9m2Dd8LNfmnd4j68u+cPCWsE46GCpPZPdat
SAg2yPD0aZBLF/gdi8TFvVES/wQ4BN7s/TqjakxLPJVfSngzX789hyB0Wo8n2rEM
uil5KNyAw4QqnMZft+f5/t8tQ5A5XzU1Sfbxb/WOYI1tR5LwRvRbXiotRxw6lHAs
H+gdM0xXp16IWpyUJuSnczR1BXZhNplZMVozObhbzzzK0XhbBVqnpJRSdP087SNW
TY55/cAudvU8cMyzkF+1WicNPhdDKwqylcwiVHhiSOUduwlip70bMdjpBlMPmblg
sYBBS8X5nfnr52+hL/Qdgx1LZ/Zws5BoHl7q1drzq+SIPyPe5r0=
=eeI8
-----END PGP SIGNATURE-----

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

Reply via email to