简体   繁体   English

设置所有小程序的默认内存限制

[英]Set default memory limit for all applets

Short version 简洁版本

How do I configure the icedtea-plugin package for ubuntu precise in such a way that it executes all applets with a specific memory limit by default? 如何配置ubuntu精确的icedtea-plugin软件包 ,使其默认情况下执行具有特定内存限制的所有小程序? Preferrably using command line tools and no graphical user interface. 最好使用命令行工具,并且不使用图形用户界面。

Long version 长版

I'm building a kiosk setup using java applets, and would like to increase the default memory limit for all these applets. 我正在使用Java Applet构建信息亭设置,并希望增加所有这些Applet的默认内存限制。 The kiosk is based on ubuntu linux, using the icedtea-plugin package as a browser plugin. 该信息亭基于ubuntu linux,使用icedtea-plugin软件包作为浏览器插件。 As building the kiosk is automated and headless, I'd rather configure it from the command line if possible. 由于自助服务亭的构建是自动化且无头的,因此,如果可能的话,我宁愿从命令行进行配置。

Here is what I've found out so far: 到目前为止,这是我发现的内容:

  • I'll probably have to specify a -Xmx… command line argument which will be used when starting the java virtual machine for the plugin. 我可能必须指定-Xmx…命令行参数,该参数将在为插件启动Java虚拟机时使用。
  • It is possible to pass such arguments using a parameter in the HTML code, ie <param name="java_arguments" value="-Xmx…"> . 可以使用HTML代码中的参数,即<param name="java_arguments" value="-Xmx…">来传递此类参数。 But that would mean modifying all my HTML files, which I'd rather avoid. 但这将意味着修改我所有的HTML文件,我宁愿避免。 And there is a good chance that I'd have to sign my code to make this work, which adds quite a lot of problems in other places of my project. 而且我很有可能必须对我的代码进行签名才能完成这项工作,这在我项目的其他地方也增加了很多问题。
  • On my desktop system, using the Oracle VM, there is an application ControlPanel which I can use to set these command line switches. 在使用Oracle VM的桌面系统上,有一个应用程序ControlPanel ,可用来设置这些命令行开关。 It seems that the configuration gets written to a file ~/.java/deployment/deployment.properties , where it is associated with the key deployment.javaws.jre.0.args . 似乎配置已写入文件~/.java/deployment/deployment.properties ,该文件与关键的deployment.javaws.jre.0.args相关联。
  • That key name is not described in the specs for that file . 文件的规范中未描述该键名。 The number 0 seems to refer to one specific JVM, as represented in one row of the table in the control panel. 数字0似乎表示一个特定的JVM,如控制面板中表的一行所示。 For each JVM, there are several values besides this args value, all sharing a common index number. 对于每个JVM,除了此args值外,还有几个值,它们共享一个共同的索引号。
  • According to this wiki section , IcedTea supports a similar file, located at ~/.icedtea/ . 根据此Wiki部分的介绍 ,IcedTea支持类似的文件,位于~/.icedtea/ Not sure whether that means ~/.icedtea/deployment.properties or rather ~/.icedtea/deployment/deployment.properties . 不知道这意味着~/.icedtea/deployment.properties还是~/.icedtea/deployment/deployment.properties IcedTea does not seem to come with a ControlPanel . IcedTea似乎不带有ControlPanel

As you can see, there are many hints as to how this might work, but so far I haven't seen any definite answer as to what will work. 正如你所看到的,有很多提示如何这可能工作,但到目前为止,我还没有看到任何明确的答案,什么工作 There are still many open questions: 仍有许多悬而未决的问题:

  • Do I have to create this icedtea deployment file? 我必须创建此icedtea部署文件吗?
  • Do I have to include a directory named deployment in the path? 我是否必须在路径中包含一个名为deployment的目录?
  • Which is the minimal set of keys that I need to specify to make this file work as intended? 为了使此文件按预期工作,我需要指定的最小键集是什么?
  • Is the args value even supported by OpenJDK, even if it is not described in the corresponding specification? 即使没有在相应的规范中说明,OpenJDK是否也支持args值?

I guess I could try out all possible combinations to see whether one of them works, but doing so will take considerable time. 我想我可以尝试所有可能的组合以查看其中一种是否有效,但是这样做将花费大量时间。 So I'm asking here, to see if someone has experience in this, and can provide a quiecker answer. 所以我在这里问,看看是否有人对此有经验,并可以提供一个快速的答案。 If not, I guess I'll answer my own question eventually, once I've tried things the hard way. 如果没有,我想一旦我用困难的方式尝试过,我最终会回答我自己的问题。

as oracle says: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/plugin.html . 如oracle所说: http : //docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/plugin.html

following environment variable should be set to add additional arguments to applets: 应该设置以下环境变量以向applet添加其他参数:

_JPI_VM_OPTIONS=-Xmx…

Moreover as the reffered site says: 此外,如转载网站所述:

Please note that you need to restart your browser after you set the environment variable. 请注意,设置环境变量后,需要重新启动浏览器。 If you are setting this environment variable in the command shell, then you must use the same command shell to launch the browser so that the browser inherits the value of environment variable. 如果要在命令外壳程序中设置此环境变量,则必须使用相同的命令外壳程序来启动浏览器,以便浏览器继承环境变量的值。

However if you doubt how to set environment variable in ubuntu, following post might be helpful: Make $JAVA_HOME easily changable in Ubuntu 但是,如果您怀疑如何在ubuntu中设置环境变量,可以参考以下文章: 使$ JAVA_HOME在Ubuntu中容易更改

I just had a look at the source code of the icedtea-web plugin. 我只是看了icedtea-web插件的源代码。 The part of the code which builds the command line seems to have no provision at all for including custom arguments, no matter their origin. 构建命令行的代码部分似乎根本没有提供包括自定义参数在内的任何规定,无论其来源如何。 So it does not matter which config files, HTML files or environment variables I edit, the code there will build the same command line to call java, disregarding all my whishes. 因此,无论我编辑哪个配置文件,HTML文件或环境变量都没有关系,在那里的代码将构建相同的命令行来调用java,而无视我的所有想法。

So if all configuration fails, what remains is hackery. 因此,如果所有配置失败,剩下的就是黑客。 One approach would be to patch the source code of the plugin, and make it include additional words into its command line. 一种方法是修补插件的源代码,并使其在命令行中包含其他单词。 For a static addition, ie a single size change, this would be fairly easy. 对于静态添加,即单个大小更改,这将非常容易。 A more general fix would include the content of some environment variable, the way Peter's answer suggests. 更一般的解决方案将包括一些环境变量的内容,就像彼得的答案所暗示的那样。 That would mean word-splitting the environment variable in question, and allocating the space for the array of words dynamically. 这意味着将单词拆分为所讨论的环境变量,并为单词数组动态分配空间。 Quite a bit of work at the C level. 在C级别上需要大量工作。

As an alternative, one could tackle this at the level of the executed binary. 作为一种替代方案,可以在执行的二进制文件级别解决此问题。 The plugin apparently has the path of the executable hard-coded into it. 该插件显然已将可执行文件的路径硬编码到其中。 In my case, this path is /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java . 在我的情况下,此路径为/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java One can rename that binary to java.orig , and put a shell script in its place, with the following content: 可以将该二进制文件重命名为java.orig ,并在其位置放置一个shell脚本,内容如下:

#!/bin/bash
for i in "$@"; do
  if [[ "${i}" == sun.applet.PluginMain ]]; then
    exec "$0.orig" -Xmx512m "$@"
  fi
done
exec "$0.orig" "$@"

One consequence of this approach is the fact that ps will no longer print these applets as java but instead as java.orig . 这种方法的一个后果是ps不再将这些小程序打印为java而是打印为java.orig Should not be a problem in most cases. 在大多数情况下应该不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM