我们正在使用Apache Axis与Web服务进行通信。它运行良好,但在一天的过程中,我们会生成1GB的临时文件。如果我们重新启动服务,这些文件将被删除,但每天需要重新启动服务以避免磁盘空间不足似乎有点愚蠢。
有没有简单的解决方法?
有没有简单的解决方法?
<bean id="....Stub" factory-bean="...." factory-method="...." scope="request">
<!-- this next element effects the proxying of the surrounding bean,
needed because .... will try to set the stub out of request scope -->
<aop:scoped-proxy/>
<constructor-arg index="0" >
<!-- The WS stub is created here, and passed to the factory-method of ... as a parameter -->
<bean class="com......ws.....Stub" scope="prototype">
<constructor-arg ref="axisConfigContext" />
</bean>
</constructor-arg>
</bean>
<!-- Exists to avoid deployment of axis jar into temp dir for each request. See AXIS2-3919 for more details. -->
<bean id="axisConfigContext"
class="org.apache.axis2.context.ConfigurationContextFactory"
factory-method="createConfigurationContextFromFileSystem">
<constructor-arg index="0"><null /></constructor-arg>
<constructor-arg index="1"><null /></constructor-arg>
</bean>
我尝试了由proudandhonour提供的创建静态块的解决方案,它非常有效。它仅为第一个请求创建临时文件。我还将Linux服务器上的uilimit更新为16000。现在我不需要删除临时文件了。
private static ConfigurationContext configContext;
static{
configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
}
每当创建新的ConfigurationContext时,都会创建临时文件。因此,请在静态块中仅创建一次ConfigurationContext,并在所有后续调用中使用它。
private static ConfigurationContext configContext;
static {
configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
}
public callService() {
Stub stub = new Stub(configContext, END_POINT_URL);
//code
}
我一直在研究同样的问题,看起来可能会在1.7.0版本中得到解决:
https://issues.apache.org/jira/browse/AXIS2-3919
我还没有尝试过,但是一旦我尝试了,我会更新这个评论。
我最近遇到了这个确切的问题,它对我们来说是一个停滞点。我有几个解决方案:
创建org.apache.axis2.deployment.util.Utils的定制版本并编辑createClassLoader函数。在axis库之前部署此函数到类路径中。此函数接受一个布尔值extractJars,如果无法复制文件(例如如果临时目录不存在),则会使用jar文件的原始副本进行工作。同样会产生一些不良后果。这个主题有许多变化,我还尝试添加一些代码来创建一个仅包含单个jar文件的副本,但我认为这个解决方案更好,因为它使用了现有的功能。以下是我的函数版本:
public static ClassLoader createClassLoader (URL[] urls,
ClassLoader serviceClassLoader,
boolean extractJars,
File tmpDir,
boolean isChildFirstClassLoading) {
List embedded_jars = Utils.findLibJars(urls[0]);
return createDeploymentClassLoader(urls, serviceClassLoader,
embedded_jars, isChildFirstClassLoading);
}
希望这能有所帮助。
除了每天重启,我找不到其他的方法。除非停止该进程,否则无法删除tmp文件。我已经更改了系统属性"java.io.tmpdir"
到另一个具有更多磁盘空间的位置,这样至少它不会因为磁盘空间不足而停止运行。
System.setProperty("java.io.tmpdir","/opt/Axis2Temp");