java - Tomcat Freezes deploying SpringBoot App -
i'm trying deply apps (4 spring boot web apps) in tomcat 9 , noticed 2 of them make tomcat log display:
17-nov-2016 00:15:07.110 info [localhost-startstop-2] org.apache.catalina.startup.hostconfig.deploywar deploying web application archive /users/viruskimera/apache-tomcat-9.0.0.m11/webapps/ftpoutbound990-0.0.1-snapshot.war
and stays way deploying doesn't display deployment finished. thing app works when doens't appear deployed completely. (i see log4j entries , files processed in monitored folder)
these apps monitor 2 different folders using java watchservice following code:
package com.ftpoutbound990.monitor;
import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.nio.file.closedwatchserviceexception; import java.nio.file.filesystems; import java.nio.file.path; import java.nio.file.paths; import java.nio.file.standardwatcheventkinds; import java.nio.file.watchevent; import java.nio.file.watchkey; import java.nio.file.watchservice; import org.apache.log4j.logger; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.value; import org.springframework.stereotype.component; import com.ftpoutbound990.client.ftpoutboundapp; @component public class monitordirectory { final static logger logger = logger.getlogger(monitordirectory.class); @autowired private ftpoutboundapp ftpoutboundapp; @value("${folder990}") private string folder990; public void startmonitoring() throws ioexception, interruptedexception { logger.info("inicio de monitoreo de archivos 990"); try (watchservice watchservice = filesystems.getdefault().newwatchservice()) { path faxfolder = paths.get(folder990); watchservice watchmyservice = filesystems.getdefault().newwatchservice(); faxfolder.register(watchmyservice, standardwatcheventkinds.entry_create); boolean valid = true; { try { watchkey watchkey = watchmyservice.take(); (watchevent event : watchkey.pollevents()) { watchevent.kind kind = event.kind(); if (standardwatcheventkinds.entry_create.equals(event.kind())) { string filename = event.context().tostring(); logger.info("archivo nuevo:" + filename); boolean isgrowing = false; long initialweight = new long(0); long finalweight = new long(0); path child = faxfolder.resolve(folder990 + filename); { initialweight = child.tofile().length(); thread.sleep(1000); finalweight = child.tofile().length(); isgrowing = initialweight < finalweight; logger.info("aun copiando archivo:" + filename); } while (isgrowing); logger.info("listo archivo:" + filename); getfile(filename); } } valid = watchkey.reset(); // thread.sleep(1000 * 10); } catch (interruptedexception | closedwatchserviceexception e) { //watchmyservice.close(); thread.currentthread().interrupt(); } } while (valid); } } public void getfile(string filename) throws ioexception { file file = new file(folder990 + filename); ftpoutboundapp.creategateway(file); } }
if remove do-while apps finished deployed! why? it's standard java watchservice code, me realize i'm missing/what's issue? thing tomcat doesn't deploy 4th app cause keeps deploying 3rd one. in advance help
edit 1: adding thread
28-dec-2016 17:57:27.558 info [main] org.apache.catalina.core.standardserver.await valid shutdown command received via shutdown port. stopping server instance. 28-dec-2016 17:57:27.559 info [main] org.apache.coyote.abstractprotocol.pause pausing protocolhandler ["http-nio-8080"] 28-dec-2016 17:57:27.613 info [main] org.apache.coyote.abstractprotocol.pause pausing protocolhandler ["ajp-nio-8009"] 28-dec-2016 17:57:27.664 info [main] org.apache.catalina.core.standardservice.stopinternal stopping service catalina 28-dec-2016 17:57:27.664 severe [containerbackgroundprocessor[standardengine[catalina]]] org.apache.catalina.startup.hostconfig.deploywars error waiting multi-thread deployment of war files complete java.lang.interruptedexception @ java.util.concurrent.futuretask.awaitdone(futuretask.java:404) @ java.util.concurrent.futuretask.get(futuretask.java:191) @ org.apache.catalina.startup.hostconfig.deploywars(hostconfig.java:744) @ org.apache.catalina.startup.hostconfig.deployapps(hostconfig.java:407) @ org.apache.catalina.startup.hostconfig.check(hostconfig.java:1595) @ org.apache.catalina.startup.hostconfig.lifecycleevent(hostconfig.java:280) @ org.apache.catalina.util.lifecyclebase.firelifecycleevent(lifecyclebase.java:92) @ org.apache.catalina.core.containerbase.backgroundprocess(containerbase.java:1136) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1372) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.processchildren(containerbase.java:1376) @ org.apache.catalina.core.containerbase$containerbackgroundprocessor.run(containerbase.java:1344) @ java.lang.thread.run(thread.java:745) 28-dec-2016 18:00:21.904 info [main] org.apache.catalina.startup.versionloggerlistener.log server version: apache tomcat/9.0.0.m11 28-dec-2016 18:00:21.907 info [main] org.apache.catalina.startup.versionloggerlistener.log server built: oct 6 2016 18:54:10 utc 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log server number: 9.0.0.0 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log os name: mac os x 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log os version: 10.9.5 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log architecture: x86_64 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log java home: /library/java/javavirtualmachines/jdk1.8.0_73.jdk/contents/home/jre 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log jvm version: 1.8.0_73-b02 28-dec-2016 18:00:21.908 info [main] org.apache.catalina.startup.versionloggerlistener.log jvm vendor: oracle corporation 28-dec-2016 18:00:21.909 info [main] org.apache.catalina.startup.versionloggerlistener.log catalina_base: /users/viruskimera/apache-tomcat-9.0.0.m11 28-dec-2016 18:00:21.909 info [main] org.apache.catalina.startup.versionloggerlistener.log catalina_home: /users/viruskimera/apache-tomcat-9.0.0.m11 28-dec-2016 18:00:21.909 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -djava.util.logging.config.file=/users/viruskimera/apache-tomcat-9.0.0.m11/conf/logging.properties 28-dec-2016 18:00:21.909 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -djava.util.logging.manager=org.apache.juli.classloaderlogmanager 28-dec-2016 18:00:21.909 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -djdk.tls.ephemeraldhkeysize=2048 28-dec-2016 18:00:21.910 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -djava.protocol.handler.pkgs=org.apache.catalina.webresources 28-dec-2016 18:00:21.910 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -dcatalina.base=/users/viruskimera/apache-tomcat-9.0.0.m11 28-dec-2016 18:00:21.910 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -dcatalina.home=/users/viruskimera/apache-tomcat-9.0.0.m11 28-dec-2016 18:00:21.910 info [main] org.apache.catalina.startup.versionloggerlistener.log command line argument: -djava.io.tmpdir=/users/viruskimera/apache-tomcat-9.0.0.m11/temp 28-dec-2016 18:00:21.910 info [main] org.apache.catalina.core.aprlifecyclelistener.lifecycleevent apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: /users/viruskimera/library/java/extensions:/library/java/extensions:/network/library/java/extensions:/system/library/java/extensions:/usr/lib/java:. 28-dec-2016 18:00:22.063 info [main] org.apache.coyote.abstractprotocol.init initializing protocolhandler ["http-nio-8080"] 28-dec-2016 18:00:22.093 info [main] org.apache.tomcat.util.net.nioselectorpool.getsharedselector using shared selector servlet write/read 28-dec-2016 18:00:22.096 info [main] org.apache.coyote.abstractprotocol.init initializing protocolhandler ["ajp-nio-8009"] 28-dec-2016 18:00:22.098 info [main] org.apache.tomcat.util.net.nioselectorpool.getsharedselector using shared selector servlet write/read 28-dec-2016 18:00:22.100 info [main] org.apache.catalina.startup.catalina.load initialization processed in 604 ms 28-dec-2016 18:00:22.145 info [main] org.apache.catalina.core.standardservice.startinternal starting service catalina 28-dec-2016 18:00:22.145 info [main] org.apache.catalina.core.standardengine.startinternal starting servlet engine: apache tomcat/9.0.0.m11 28-dec-2016 18:00:22.224 info [localhost-startstop-1] org.apache.catalina.startup.hostconfig.deploywar deploying web application archive /users/viruskimera/apache-tomcat-9.0.0.m11/webapps/ftpoutbound990-0.0.1-snapshot.war 28-dec-2016 18:00:26.346 info [localhost-startstop-1] org.apache.jasper.servlet.tldscanner.scanjars @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: spring boot :: (v1.3.6.release)
the tomcat deployer thread seems invoking startmonitoring
method. intended, method never returning , hence deployment not getting complete.
to fix this, need run monitoring method in separate (or background) thread.
below refactored example may helpful.
aside note, single instance of watcherservice instances can used watching multiple directories.
import java.io.file; import java.io.ioexception; import java.nio.file.filesystems; import java.nio.file.path; import java.nio.file.paths; import java.nio.file.standardwatcheventkinds; import java.nio.file.watchevent; import java.nio.file.watchkey; import java.nio.file.watchservice; import java.util.concurrent.executorservice; import java.util.concurrent.executors; import javax.annotation.postconstruct; import javax.annotation.predestroy; import org.apache.log4j.logger; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.value; import org.springframework.stereotype.component; @component public class monitordirectory { final static logger logger = logger.getlogger(monitordirectory.class); @autowired private ftpoutboundapp ftpoutboundapp; @value("${folder990}") private string folder990; private watchservice watchservice; private executorservice eventloop = executors.newfixedthreadpool(1); @postconstruct public void init() throws ioexception, interruptedexception { watchservice = filesystems.getdefault().newwatchservice(); eventloop.submit((runnable) () -> { try { startmonitoring(); } catch (exception e) { logger.error("error...", e); } }); } @predestroy public void destroy() throws ioexception { eventloop.shutdownnow(); if (watchservice != null) { watchservice.close(); } } public void startmonitoring() throws ioexception, interruptedexception { logger.info("inicio de monitoreo de archivos 990"); path faxfolder = paths.get(folder990); watchkey watchkey = faxfolder.register(watchservice, standardwatcheventkinds.entry_create); boolean valid = true; { (watchevent<?> event : watchkey.pollevents()) { watchevent.kind<?> kind = event.kind(); if (standardwatcheventkinds.entry_create.equals(kind)) { string filename = event.context().tostring(); logger.info("archivo nuevo:" + filename); boolean isgrowing = false; long initialweight = new long(0); long finalweight = new long(0); path child = faxfolder.resolve(folder990 + filename); { initialweight = child.tofile().length(); thread.sleep(1000); finalweight = child.tofile().length(); isgrowing = initialweight < finalweight; logger.info("aun copiando archivo:" + filename); } while (isgrowing); logger.info("listo archivo:" + filename); getfile(filename); } valid = watchkey.reset(); } } while (valid); } public void getfile(string filename) throws ioexception { file file = new file(folder990 + filename); ftpoutboundapp.creategateway(file); } }
Comments
Post a Comment