tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Gogan" <vinc...@oldorchardtech.com>
Subject RE: Asynchronous statistics logger
Date Thu, 02 Dec 2004 15:17:39 GMT
I'll agree using the Context Listener for starup/shutdown but you probably
don't need to add JMS to the mix.

As a first approach, you could simply switch all your logging to log4j. I
haven't used it that much but I know it has many types of appenders
(including JMS). Log4j is thread safe and is reported to scale well.

If you need to go beyond that, then you will probably want to read up
on Producer/Consumer type issues in a multithreaded environment. There
are books written on these types of issues but for your type of situation
the
problem boils down to how you decouple the producers (the threads adding
to the log) from the consumer (the TimerTask writing the log). A simple
solution is to put a queue between the two and make sure that
nothing is locked up for too long. Watch out for a common implementation
mistake: having the consumer lock the queue while processing it. A
better solution is to have the consumer take the queue and replace it with
an empty one.


Hope this helps,

Vincent

> -----Original Message-----
> From: Allistair Crossley [mailto:Allistair.Crossley@QAS.com]
> Sent: Thursday, December 02, 2004 5:11 AM
> To: Tomcat Users List
> Subject: RE: Asynchronous statistics logger
>
>
> this strikes me as being something JMS would handle well, but
> Tomcat doesn't support JMS by default. I have seen people
> installing openJMS on Tomcat though.
>
> as for the startup/shutdown, that's going to be a Context
> Listener you want to implement and add to web.xml with <listener>.
>
> that's about all i can offer on this, sorry :)
>
> > -----Original Message-----
> > From: Michael Cornell [mailto:michael.cornell@estafet.com]
> > Sent: 02 December 2004 10:04
> > To: tomcat-user@jakarta.apache.org
> > Subject: Asynchronous statistics logger
> >
> >
> > Hi,
> >
> > I am trying to implement an asynchronous statistics logger
> > that would load
> > on startup and be destroyed on shutdown of tomcat.  This
> > logger then needs
> > to write to a log file / to disk / to log4j every x seconds with these
> > statistics.
> >
> > Methods to add some statistic to it need to be accessible by all other
> > classes in the same context (eg public static void addPageHit(String
> > whatPage, int howBigWasIt); )
> >
> > I have already tried writing an asynchronous Singleton, but
> > this has caused
> > major havoc with threading issues (jdk1.4.2 tomcat 5.0.25
> > redhat linux 9.0).
> > In addition I know this is not good practice.  This singleton
> > was using the
> > Timer and TimerTask for its implementation.
> >
> > What is the best practice for implementing this sort of class ?
> >
> > Thanks
> >  Michael
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
> >
>
>
> <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE>
> -------------------------------------------------------
> QAS Ltd.
> Developers of QuickAddress Software
> <a href="http://www.qas.com">www.qas.com</a>
> Registered in England: No 2582055
> Registered in Australia: No 082 851 474
> -------------------------------------------------------
> </FONT>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>



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


Mime
View raw message