如何在不退出JVM运行Java程序多次? [英] How to run a Java program multiple times without JVM exiting?

查看:401
本文介绍了如何在不退出JVM运行Java程序多次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Java程序的Test.class ,如果我用下面的脚本

 为我在1..10

    Java测试
DONE

在JVM将每次调用 Java测试时间退出。

我要运行 Java测试多次不退出JVM,这样一来,在以前运行的优化方法,可以通过以后的运行使用,并可能进一步什么优化。


解决方案

 公共类的runTest
 {
    公共静态无效的主要(字串[] args)
      {
          的for(int i = 1; I< = 10;我++)
              Test.main(参数);
      }
 }

这应该这样做。可以调用测试类的主要功能与您传递给主函数相同的参数。这是包装另一海报提及。

Suppose I have a Java program Test.class, if I used the below script

for i in 1..10
do
    java Test
done

the JVM would exit each time java Test is invoked.

What I want is running java Test multiple times without exiting the JVM, so that, the optimized methods in prior runs can be used by later runs, and possibly be further optimized.

解决方案

public class RunTest
 {
    public static void main(String[] args)
      {
          for(int i=1; i<=10; i++)
              Test.main(args); 
      }
 }

This should do it. You can call the Test class' main function with the same arguments you pass to your main function. This is the "wrapper" that another poster referred to.

这篇关于如何在不退出JVM运行Java程序多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆