tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Directory watcher app
Date Tue, 15 Oct 2013 16:21:21 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Honyk,

On 10/14/13 3:21 PM, honyk wrote:
> in my web app I use Java 7 directory watcher feature.
> 
> When the final war file is placed into Webapps folder and Tomcat is
> started, it freezes as it waits forever for any directory changes
> (the app is loaded on tomcat startup).

Thread dump?

> I use the following workaround - calling my watcher code in a new
> Thread (in the context init phase).
> 
> It does the job, but I am not sure if this is the best solution.
> Couldn't be the same effect achieved using specific tomcat
> options?
> 
> What do you think?
> 
> Thanks, Jan
> 
> 
> package my.util.jobticketprocessor;
> 
> import javax.servlet.ServletContextEvent; import
> javax.servlet.ServletContextListener; import org.slf4j.Logger; 
> import org.slf4j.LoggerFactory;
> 
> public class ContextListener implements ServletContextListener {
> 
> private static final Logger LOGGER = 
> LoggerFactory.getLogger(ContextListener.class.getName()); private
> Thread threadA;
> 
> @Override public void contextInitialized(ServletContextEvent event)
> { LOGGER.info("Watcher - right before the init.");
> 
> threadA = new Thread(new Runnable() { @Override public void run()
> { LOGGER.info("Thread - right before the init."); 
> JobTicketWatcher.getInstance().initProcessor();

This isn't part of the Java API. What does
JobTicketWatcher.initProcessor do?

- -chris

> LOGGER.info("Thread - right after the init."); } }, "Thread A");
> 
> threadA.start();
> 
> LOGGER.info("Watcher has been initialized successfully."); }
> 
> @Override public void contextDestroyed(ServletContextEvent event)
> { JobTicketWatcher.getInstance().terminateProcessor(); try { 
> threadA.join(); LOGGER.info("Thread has been terminated."); } catch
> (InterruptedException e) { LOGGER.error("Thread terminating has
> failed."); } LOGGER.info("Watcher has been terminated."); } }

If you are "joining" a thread in your contextDestroyed method, then it
stands to reason that you are expecting it to be long-running. Since
the file-change notification API is supposed to be asynchronous, why
do you expect that thread to run for the life of your webapp?

Furthermore, what steps are you taking to make sure that your thread
actually stops, and that contextDestroyed() doesn't then hang forever?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJSXWt+AAoJEBzwKT+lPKRYuWgP/j23h+g37ompw9IDw7ZZ81Ms
Aw4qg8NHa5OiAxRs5vyT6ymscLM++JjdDVy1TBxFC7lMDTsgeoPgjRPeZv+7GceQ
A0QscsWL7j8iT5fqEOEJhtLHaO5j9SNrjeSNUCY9JfdgBtoMtg0NWgvCfg//qcKY
iDWXxgRInF3/2/iHFJAvd4S+dmsXay4vgJ0EnSv9z02xsuBbJIthphP63x2jzhI2
QqMEsnNED2a0dqZsrhOAUBU9rdLaAX2Sg8p7z523pZXS6KKfAhKfTfzBWI3QG+03
AvZD6LJF2jJgjzIrkO2KdnhVUH8R6ZgaFdPC/GkLgaTVbVQMNSLz/9NXDCZvzEIg
M6M5tshGWqEIbWNuSRYgDzpnKVNKehST1XNWcF6x8EKNgcZNmdtUNjM/jcChPPS4
jJ/ybkfxWN7grodadtwzvFQEu49RPIcTfhzrIQYQfz2K8uaFJ/c065Uvy5ddz4RW
8CxrhFBYX5sdYBsIomuYw5RFzeBkP0gR+2VAM4fDAjs2FpUHSWbW37qWt26t1wAF
AtZ3LX2tHtenK92fRtWIjjQmkkbwLPUJYL9jYDYmKkeyJ35ClHeJhT24YR10uR4t
tn2+Jor4v+nXetHQste5BLnrmKScA0eK773usNuNWC17ftdbtdGy1D5ep8lTKBcX
a6xX2cjd3TQ1kiMDq1Uq
=uAEO
-----END PGP SIGNATURE-----

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


Mime
View raw message