I have a game implemented in Java that was having a problem when running too much code from scripts: depending on the script language, the game could have these "hiccups" where the game would freeze for a couple frames every now and then, making the game "jerky" at times.
我有一个用Java实现的游戏,当从脚本运行太多代码时遇到问题:根据脚本语言,游戏可能会有这些“打嗝”,游戏会不时地冻结几帧,使得游戏“生涩”有时。
After some research, I discovered that was happening when the Garbage Collector decided to run. After some more research and testing, I discovered that using the incremental garbage collector (by using the -Xincgc VM parameter) fixed the problem. Yes, I am aware it makes the GC run about 10% slower, but it is the cost I pay.
经过一些研究,我发现当垃圾收集器决定运行时就会发生这种情况。经过一些研究和测试后,我发现使用增量垃圾收集器(通过使用-Xincgc VM参数)修复了问题。是的,我知道它使GC的运行速度慢了10%,但这是我付出的代价。
With that background information, now what I want to do is package the game in a .jar like I have been doing so far, but I know no way of making the application use the incremental GC without using -Xincgc, and I didn't want to create .bat/.sh files where before the user only had to double-click the .jar.
有了这些背景信息,现在我要做的就是将游戏打包成.jar就像我到目前为止所做的那样,但我知道没有办法让应用程序使用增量GC而不使用-Xincgc,而我没有想要在用户只需双击.jar之前创建.bat / .sh文件。
Is there any way to make the .jar run with the incremental GC without needing some kind of loader (.bat/.sh) or wrapper around it? Is there some way to include that parameter in the .jar?
有没有办法让.jar运行增量GC而不需要某种加载器(.bat / .sh)或它周围的包装器?有没有办法在.jar中包含该参数?
6 个解决方案
#1
No, there's no way to do that. VM arguments can only be supplied as command-line parameters to JVM invocation: Java Tool
不,没有办法做到这一点。 VM参数只能作为命令行参数提供给JVM调用:Java Tool
#2
You can definitely do this with JNLP, which can be configured to add a shortcut to the desktop and automatically keep jars up to date, among other things.
您绝对可以使用JNLP执行此操作,JNLP可以配置为向桌面添加快捷方式,并自动保持罐子最新等。
#3
From just a jar file, you can't do this. Adding Java WebStart can allow you to add java VM commands. If you are not against wrapping the jar in an executable Launch4J will wrap the jar in a executable as well. It only makes a windows exe, but it can make it on linux or windows. I haven't found a good alternative for linux.
从jar文件中,你不能这样做。添加Java WebStart可以允许您添加Java VM命令。如果您不反对将jar包装在可执行文件中,则Launch4J也会将jar包装在可执行文件中。它只生成一个Windows exe,但它可以在linux或windows上生成。我还没有找到一个很好的替代Linux。
#4
I don't know of too many java apps outside of internal coorporate or dev stuff that people run via clicking a jar. Even a shortcut can specify this. Fancier options exist that let you create an exe, run as a service, or even wrap the whole thing in an installer... if we are talking windows, similar things exist for linux.
我不知道内部coorporate之外的太多java应用程序或人们通过点击jar运行的开发人员。即使是快捷方式也可以指定。存在的Fancier选项允许您创建一个exe,作为服务运行,甚至将整个事物包装在一个安装程序中...如果我们正在谈论Windows,那么Linux存在类似的东西。
#5
Besides Java Web Start, you could consider wrapping with JSMooth. It gives an EXE which in turn invokes the JVM - you can provide arguments there.
除了Java Web Start之外,您还可以考虑使用JSMooth进行包装。它给出了一个EXE,它又调用JVM - 你可以在那里提供参数。
#6
One option - I always wondered - is to re-run the jar program with Runtime.exec() call when the parameters are inadequate? Never tried it but seems possible.
一个选项 - 我总是想知道 - 当参数不合适时,用Runtime.exec()调用重新运行jar程序?从未尝试过,但似乎有可能。
#1
No, there's no way to do that. VM arguments can only be supplied as command-line parameters to JVM invocation: Java Tool
不,没有办法做到这一点。 VM参数只能作为命令行参数提供给JVM调用:Java Tool
#2
You can definitely do this with JNLP, which can be configured to add a shortcut to the desktop and automatically keep jars up to date, among other things.
您绝对可以使用JNLP执行此操作,JNLP可以配置为向桌面添加快捷方式,并自动保持罐子最新等。
#3
From just a jar file, you can't do this. Adding Java WebStart can allow you to add java VM commands. If you are not against wrapping the jar in an executable Launch4J will wrap the jar in a executable as well. It only makes a windows exe, but it can make it on linux or windows. I haven't found a good alternative for linux.
从jar文件中,你不能这样做。添加Java WebStart可以允许您添加Java VM命令。如果您不反对将jar包装在可执行文件中,则Launch4J也会将jar包装在可执行文件中。它只生成一个Windows exe,但它可以在linux或windows上生成。我还没有找到一个很好的替代Linux。
#4
I don't know of too many java apps outside of internal coorporate or dev stuff that people run via clicking a jar. Even a shortcut can specify this. Fancier options exist that let you create an exe, run as a service, or even wrap the whole thing in an installer... if we are talking windows, similar things exist for linux.
我不知道内部coorporate之外的太多java应用程序或人们通过点击jar运行的开发人员。即使是快捷方式也可以指定。存在的Fancier选项允许您创建一个exe,作为服务运行,甚至将整个事物包装在一个安装程序中...如果我们正在谈论Windows,那么Linux存在类似的东西。
#5
Besides Java Web Start, you could consider wrapping with JSMooth. It gives an EXE which in turn invokes the JVM - you can provide arguments there.
除了Java Web Start之外,您还可以考虑使用JSMooth进行包装。它给出了一个EXE,它又调用JVM - 你可以在那里提供参数。
#6
One option - I always wondered - is to re-run the jar program with Runtime.exec() call when the parameters are inadequate? Never tried it but seems possible.
一个选项 - 我总是想知道 - 当参数不合适时,用Runtime.exec()调用重新运行jar程序?从未尝试过,但似乎有可能。