我有几个使用嵌入式jetty实现的服务,这些服务在Windows Server中运行时会导致磁盘空间问题。问题似乎是,当服务器线程完成或服务器进程停止时,临时文件和文件夹都没有被清除。
例如,如果我在Windows上使用本地用户帐户运行我的服务,则在C:\ Windows \ Temp中为我运行的每个服务创建一个文件夹,其名称模式为axis-。在这些文件夹中是特定服务的.jar文件的副本 - 服务已处理的每个请求的一个副本。
由于我没有使用servlet容器(没有WAR文件)部署它们,所以我没有配置文件来控制Jetty的行为。是否有一些其他编程方式来控制临时文件的清理?
这是我的服务编码的一个例子 - 所有这些都是相同的模式。
Server quoteServer = new Server(ratingServerPort);
HandlerList handlers = new HandlerList();
PingHandler pingHandler = new PingHandler();
pingHandler.setLogger(log);
handlers.addHandler(pingHandler);
QuoteHandler quoteHandler = new QuoteHandler();
quoteHandler.setLogger(log);
quoteHandler.setMongo(mongo);
quoteHandler.setMorphia(morphia);
quoteHandler.setMongoHostname(mongoHostname);
quoteHandler.setMongoPort(mongoPort);
quoteHandler.setMileageHost(mileageHost);
quoteHandler.setMileagePort(mileagePort);
quoteHandler.setTransitURL(transitURL);
quoteHandler.setAuthKeys(authKeys);
handlers.addHandler(quoteHandler);
BangitHandler bangit = new BangitHandler();
handlers.addHandler(bangit);
quoteServer.setHandler(handlers);
try {
quoteServer.start();
quoteServer.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
只有基于WebAppContext
的部署才能在Jetty本身内创建临时文件。
(由servlet规范和内部WebInfConfiguration
类提供)。
如果文件名以axis-
开头,那么它可能是您的项目可能具有的轴库创建的临时目录。
查看过去的答案(answer 2 by @anton和answer 3 by @code-mode似乎与您的特定用例更相关,然后是接受的答案)...