如何删除apache轴tmp文件而不重新启动

时间:2012-01-20 01:04:13

标签: java web-services apache axis

我们正在使用apache轴与Web服务进行通信。它工作正常,但在一天的过程中我们生成1GB的临时文件。如果我们重新启动服务,但是每天都需要重新启动服务,那么这些文件就会被删除,所以我们不会耗尽磁盘空间似乎有点傻。

对此有一个简单的解决方法吗?

7 个答案:

答案 0 :(得分:5)

我们找到了一种避免生成这些文件的程序化方法 - 这听起来像是一种更好的管理方式。我发布了in the comments AXIS2-3919个{{3}}问题,但会在此处复制以防万一:


实际上,每次创建AXIS配置上下文时,文件都会部署到temp文件夹。此外,似乎生成的Stub可以通过构造函数接受现有的配置对象。因此,以下Spring配置帮助我们解决了这个问题(删除了无关的bean和类名):

<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>

答案 1 :(得分:3)

每当创建新的ConfigurationContext时,都会创建临时文件。因此,在静态块中只创建一次ConfigurationContext,并在所有后续调用中使用它。

private static ConfigurationContext configContext;

static {
     configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
}

public callService() {
    Stub stub = new Stub(configContext, END_POINT_URL);
    //code
}

如果您没有传递上下文,则axis2将在每次调用时创建新的上下文。

答案 2 :(得分:2)

我尝试了创建静态块的解决方案(由proudandhonour提供)并且效果很好。它仅为第一个请求创建临时文件。我还将Linux服务器上的uilimit更新为16000.现在我不需要删除临时文件。

private static ConfigurationContext configContext; 
static{   
   configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);  
}

答案 3 :(得分:1)

我一直在看同样的问题,看起来它可能会在1.7.0版本中修复:

https://issues.apache.org/jira/browse/AXIS2-3919

我还没有尝试过,但是一旦我这样做,我就会更新这条评论。

答案 4 :(得分:0)

如果你知道临时目录路径,你可以每隔6,12,从..运行 rm -rf / path /到/ temp / *

或者如果达到特定大小,您可以编写运行在linux系统上的bashscript来清空此目录。并把它放在crontab中。

答案 5 :(得分:0)

除了每天重新启动之外,我没有找到任何其他方式。除非您停止该过程,否则将不允许删除tmp文件。我已将系统属性"java.io.tmpdir"更改为具有更多磁盘空间的其他位置,因此至少它不会耗尽磁盘空间。

System.setProperty("java.io.tmpdir","/opt/Axis2Temp"); 

其次还有另外一个与这些文件有关的问题,在runnng app几个小时之后会抛出太多打开的文件异常,如下所示:

  

org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7 org.apache.axis2.deployment.util.Utils。[createClassLoader](856) - 将jar解压缩到临时目录的异常:java.io.FileNotFoundException:/ tmp /axis2-tmp-9161756920591296931.tmp/axis21477916618765108874addressing-1.6.0.mar(打开文件过多):切换到备用类加载机制

     

org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7 org.apache.axis2.deployment.util.Utils。[createClassLoader](860) - java.io.FileNotFoundException:/ tmp / axis2-tmp-9161756920591296931。 tmp / axis21477916618765108874addressing-1.6.0.mar(打开的文件过多)

为了解决这个问题,我已将打开文件的ulimit增加到4000.

答案 6 :(得分:0)

我最近遇到了这个确切的问题,它对我们来说是个显示器。我有几个解决方案:

  1. 将java.io.tmpdir设置为不存在的目录。这可能会产生一些不良后果!
  2. 创建org.apache.axis2.deployment.util.Utils的定制版本并编辑createClassLoader函数。在轴库之前的类路径中部署它。这个函数接受一个布尔值extractJars,它导致文件被复制,如果不可能(例如,如果tmp目录不存在),则类加载器将处理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);
    }
    
  3. 我希望这会有所帮助。