Jetty 隔几天凌晨定时出现404错误

一、问题及原因分析
最近一个老的应用被部署到jetty后定时出现404错误,老应用的代码比较糟糕,也出过不少问题,本以为是程序问题、
查询负载、线程、dump文件、io都没有明显异常,挺奇怪一直没找到原因
查看了jetty启动是war解压目录/tmp/jetty-0.0.0.0-8100-hrs-web.war-_hrs-any-/webapp
因为在/tmp目录,应该是有问题,linux会清除/tmp目录。

二、解决方法
问题找到了,那如何指定war解压目录? 在网上找到一份详细说明,如下:
http://docs.codehaus.org/display/JETTY/Temporary+Directories

Jetty itself has no temporary directories, but each web application can be assigned a directory into which the war is unpacked, JSPs compiled on-the-fly etc.

The algorithm for determining a webapp’s temporary directory location is as follows:

Try to use an explicit directory specifically for this webapp:
Iff webapp.getTempDirectory() is set, use it. Do NOT delete it on jvm exit.
Iff javax.servlet.context.tempdir context attribute is set for this webapp && exists && writeable, then use it. Do NOT delete on jvm exit.
Create a directory based on global settings. The new directory will be called “Jetty_”host””port””context””+virtualhost :
Iff $(jetty.home)/work exists create the directory there. Do NOT delete on jvm exit. Do NOT delete contents if dir already exists.
Iff WEB-INF/work exists create the directory there. Do NOT delete on jvm exit. Do NOT delete contents if dir already exists.
Else create dir in $(java.io.tmpdir). Set delete on jvm exit. Delete contents if dir already exists.
It is important to note that a temporary directory will have its contents deleted when the webapp is stopped unless either:

it is called “work”
it pre-existed the deployment of the webapp
Once a tempory directory has been allocated, a File instance for it is set and retrievable as the javax.servlet.context.tempdir attribute of the web application.

最后我选择了在$(jetty.home)/work下建立一个统一的work目录,这样最方便部署,jetty 每台机子统一安装就可以。

本文作者: GavinDong

版权属于: GavinDong博客

文章链接: https://gavindong.com/1131.html

如果使用过程中遇到问题,可 **点击此处** 交流沟通。

版权所有,转载时必须以链接形式注明作者和原始出处及本声明。

(0)

相关文章

发表回复

登录后才能评论