On 09/06/2011 18:44, Calum wrote:
> On 9 June 2011 09:11, Pid <p...@pidster.com> wrote:
>> Eh?  Why would you need to put Tomcat specific dependencies in a spec
>> compliant Servlet container?  The above is simply not true.
>>
>> The OP use of a ServletContextListener is perfectly valid, (even if the
>> rest of the code is a little odd).
> 
> Is it better to have a separate class that implements the Listener,
> and sets running = false in the Threads, or just have the thread class
> implement the listener itself?

If we're talking abstractly, rather than in reference to the OPs code,
then for most cases I'd suggest that a ServletContextListener would be
best implemented as a thread controller, rather than as a thread.

See java.util.concurrent, e.g. Executors.class, ExecutorService.class.

The contextInitialized() method of the SCL would create & start the
service, configuring threads etc & contextDestroyed() would shut the
service down - it's a thread pool manager, so takes care of stopping the
threads, if you've implemented them correctly.


Remember to catch InterruptedException in each threads run() method and
take care to clean up properly & stop the work it does.

If you implement a ThreadFactory you can name threads & make your life
easier when/if Tomcat complains they don't shutdown properly.


p


> Or are there not really any pros or cons either way?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to