简体   繁体   English

重新部署战争时是否需要重新启动tomcat?

[英]Is it necessary to restart tomcat when redeploy a war?

I know Tomcat can reload the .war file when redeploy it, I don't need to kill the Tomcat process and restart it. 我知道Tomcat可以在重新部署.war文件时重新加载它,而无需终止Tomcat进程并重新启动它。 I can remove the .war , wait for Tomcat to undeploy it, and copy the new .war to the web path. 我可以删除.war ,等待Tomcat取消部署,然后将新的.war复制到Web路径。 But, after many times of trivial update war without restart the Tomcat, is it possible that Tomcat will not release the memory effectively or cause some performance issues? 但是,经过多次琐碎的更新大战而又没有重启Tomcat,Tomcat是否可能无法有效地释放内存或导致某些性能问题? Assume there is only one war application in one Tomcat instance. 假设在一个Tomcat实例中只有一个war应用程序。

The basic problem is that Java does currently not provide any kind of isolation between the parts of code running in a Java Virtual Machine (JVM) , in the same way that an operating system does with processes . 基本问题是,Java当前没有像在操作系统中对进程进行处理的方式那样,在Java虚拟机(JVM)中运行的代码部分之间提供任何形式的隔离。 You can kill a process without affecting another process under Windows/Linux/etc. 您可以杀死一个进程而不会影响Windows / Linux / etc下的另一个进程。 All you can do is ensuring that things can be garbage collected. 您所要做的就是确保可以垃圾回收。

For Tomcat the way that WAR 's are being handled - according to the various specifications - require that each war has its own classloader that is responsible for running that code. 对于Tomcat,根据各种规范 ,处理WAR的方式要求每次战争都拥有自己的类加载器,该类加载器负责运行该代码。 When the WAR is undeployed the final result should be that that class loader should be garbage collected. 取消部署WAR时,最终结果应该是应该垃圾回收该类加载器。

Unfortunately the garbage collector can only handle objects that are completely unreferenced, and there is a large set of subtle bugs that can be present in WAR code that can prohibit this, and then every redeploy cause another classloader to be created and none destroyed so you have a memory leak. 不幸的是, 垃圾收集器只能处理完全未引用的对象,并且WAR代码中可能存在大量微妙的错误,这些错误可以阻止这种情况,然后每次重新部署都会导致创建另一个类加载器,并且没有破坏任何类加载器,因此您已经内存泄漏。 A lot of effort has gone into detecting and working around these type of bugs inside Tomcat itself, but it is close to impossible to do 100% right without JVM support. 在检测和解决Tomcat自身内部的此类错误方面已经付出了很多努力,但是如果没有JVM支持,几乎不可能100%正确地做到这一点。

The only cure besides fixing the WAR is to restart the JVM. 除了修复WAR之外,唯一的解决方法是重新启动JVM。

You can watch the memory usage with VisualVM even in production to see what happens over time with the Tomcat JVM. 您甚至可以在生产中使用VisualVM监视内存使用情况,以了解随着时间的推移Tomcat JVM会发生什么。

Yes. 是。 It is far cleaner to stop Tomcat, deploy your new war, then restart Tomcat. 停止Tomcat,部署新战争,然后重新启动Tomcat更为清洁。 One drawback is much of your application classes by default won't be loaded till a new request comes in to hit your application but its not a huge issue. 一个缺点是,默认情况下,您的许多应用程序类在新请求打入您的应用程序之前不会加载,但这并不是一个大问题。 Just means theres a few seconds of startup on the very first request to your new WAR. 只是意味着对您的新WAR的第一个请求需要几秒钟的启动时间。 This is how we deploy wars in production. 这就是我们在生产中部署战争的方式。

Also allows us to setup health-checking in the logs if the new war prevents Tomcat from starting up correctly then we rollback the war knowing theres an issue, but thats a separate topic. 如果新的战争阻止了Tomcat正常启动,还允许我们在日志中设置运行状况检查,然后知道有问题就回滚了战争,但这就是一个单独的主题。

What About Down Time? 那停机时间呢?

This might be out of scope of your question but when you want to prevent users from seeing any downtime you would run multiple instance of tomcat and deploy and restart one at a time. 这可能不在您的问题范围内,但是当您要阻止用户看到任何停机时间时,您将运行多个tomcat实例并一次部署并重新启动一个实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM