我将我的一个程序从独立的Java应用程序移植到Java applet。应用程序处理大型图像文件,因此我需要更多的堆空间,因此将它们加载到内存中。然后将图像用作openGL窗口中的纹理数据,我使用了JOGL
应用程序在eclipse中运行良好(作为applet以及独立)并且如果我将独立应用程序导出为可执行jar。我在各种系统上测试了这个(Windows XP 32有4 gig ram,Windows XP 64有12 gig ram,Windows 7 64 bit有4和8 gig ram)。
导出程序的applet版本时出现问题。在我签署jar并尝试在浏览器中运行它(测试的Firefox和IE)之后,应用程序总是在上述64位计算机上崩溃并出现OutOfMemory异常。
在Windows XP 32bit机器上,但是它经过了一些摆弄但我不知道为什么,因为我所做的只是尝试不同的解决方案,不知何故其中一个工作,即使这样也会导致崩溃以前的尝试。
我尝试增加堆空间的方法有四种
在我试过的html文件中:
<PARAM name="java_arguments" value="-Xmx1600m">
哪个不起作用。
然后我尝试使用-Xmx1600M参数通过Java菜单(开始 - &gt;控制面板 - &gt; Java选项卡 - &gt; Java运行时环境设置)直接增加堆。这顶帽子也没什么影响。
之后,我使用了Jogamp的人员的jnlp文件。在那里我添加了
<j2se version="1.6+" java-vm-args="-Xmx1600m"
href="http://java.sun.com/products/autodl/j2se"/>
在资源标记内。这最初也没有效果。
最后我添加了
<j2se version="1.6+" initial-heap-size="256M" max-heap-size="1600M"
href="http://java.sun.com/products/autodl/j2se"/>
在资源标记内部,经过几次尝试后,我在四个不同的解决方案中盘旋并清除它工作的applet缓存(但仅限于32位WinXP机器上)。
但我没有成功尝试在64位机器上运行applet,我绝对不知道现在该做什么,因为经过一些研究后,这四种方法似乎是唯一的一种。
提前感谢您的帮助。
我将添加两个jnlp文件和启动applet的html文件。
HTML:
<html>
<head>
<title>Some title</title>
</head>
<body>
<center>
<applet code="guiconcepts/AppletTest.class"
width=1600
height=1010
archive="SConfigTest.jar">
<param name="codebase_lookup" value="false">
<param name="subapplet.classname" value="SConfigTest">
<param name="subapplet.displayname" value="SConfigTest">
<param name="noddraw.check" value="true">
<param name="progressbar" value="true">
<param name="jnlpNumExtensions" value="1">
<param name="jnlpExtension1"
value="http://download.java.net/media/jogl/jsr-231-2.x-
webstart/jogl-core.jnlp">
<param name="java_arguments" value="-Dsun.java2d.noddraw=true">
<param name="jnlp_href" value="AppletTest.jnlp">
</applet>
</center>
</body>
</html>
AppletTest.jnlp:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.5+" codebase="./"
href="AppletTest.jnlp">
<information>
<title>Some title</title>
<vendor>Some vendor</vendor>
<homepage href="http://www.somePage.com"/>
<description>Java Applet Test</description>
<description kind="short">Test of a Java Applet</description>
<offline-allowed/>
</information>
<update check="background" policy="always"/>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<property name="sun.java2d.noddraw" value="true"/>
<extension name="JOGL" href="JOGL.jnlp" />
<jar href="jai_core.jar" />
<jar href="jai_codec.jar" />
<jar href="mlibwrapper_jai.jar" />
<jar href="SConfigTest.jar" main="true"/>
</resources>
<applet-desc
name="AppletTest"
main-class="guiconcepts.AppletTest"
width="1600"
height="1010">
</applet-desc>
</jnlp>
JOGL.jnlp:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="./"
href="JOGL.jnlp">
<information>
<title>JOGL libraries</title>
<vendor>JogAmp Community</vendor>
<homepage href="http://jogamp.org/"/>
<description>JOGL libraries</description>
<description kind="short">
All JARs and native libraries for JOGL.</description>
<offline-allowed/>
</information>
<update check="background" policy="always"/>
<security>
<all-permissions/>
</security>
<resources>
<jar href="gluegen-rt.jar" />
<jar href="jogl.all.jar" />
</resources>
<resources os="Windows" arch="x86">
<nativelib href = "gluegen-rt-natives-windows-i586.jar" />
<nativelib href = "jogl-all-natives-windows-i586.jar" />
</resources>
<resources os="Windows" arch="amd64">
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" />
<nativelib href = "jogl-all-natives-windows-amd64.jar" />
</resources>
<resources os="Windows" arch="x86_64">
<nativelib href = "gluegen-rt-natives-windows-amd64.jar" />
<nativelib href = "jogl-all-natives-windows-amd64.jar" />
</resources>
<resources os="Linux" arch="i386">
<nativelib href = "gluegen-rt-natives-linux-i586.jar" />
<nativelib href = "jogl-all-natives-linux-i586.jar" />
</resources>
<resources os="Linux" arch="x86">
<nativelib href = "gluegen-rt-natives-linux-i586.jar" />
<nativelib href = "jogl-all-natives-linux-i586.jar" />
</resources>
<resources os="Linux" arch="amd64">
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" />
<nativelib href = "jogl-all-natives-linux-amd64.jar" />
</resources>
<resources os="Linux" arch="x86_64">
<nativelib href = "gluegen-rt-natives-linux-amd64.jar" />
<nativelib href = "jogl-all-natives-linux-amd64.jar" />
</resources>
<resources os="Mac OS X" arch="i386">
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" />
<nativelib href = "jogl-all-natives-macosx-universal.jar" />
</resources>
<resources os="Mac OS X" arch="x86_64">
<nativelib href = "gluegen-rt-natives-macosx-universal.jar" />
<nativelib href = "jogl-all-natives-macosx-universal.jar" />
</resources>
<component-desc />
</jnlp>
[编辑:]似乎我发现了导致问题的原因(但没有解决方案)。如果我使用任何给定浏览器的32位版本启动applet,浏览器将启动32位jre,这无法应对jnlp-files中的jvm-settings。
这真的很奇怪,因为在32位机器上调用32位jvm工作得很好。
如果我使用64位浏览器(如IE 64位版本或Nightly Firefox 64版本)启动applet,则会调用“正确”的jvm并运行正常。
所以我想真正的问题是如何从32位浏览器启动64位jvm(这甚至可能吗?)。
但是我写了一个小测试程序来重现错误。程序将大图像存储在数组中。使用32位浏览器,您应该可以加载2-3个图像,直到出现OutOfMemoryException。如果你想测试程序,你必须创建一个jar并在之后签名并将其命名为SConfigTest.jar。
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;
public class AppletTest extends JApplet {
private static final long serialVersionUID = 1L;
public AppletTest() {
}
public void init() {
/*
* settings if using a proxy server
*/
/*
Properties p = System.getProperties();
p.put("http.proxyHost", "proxy.address.com");
p.put("http.proxyPort", "8080");
System.setProperties(p);
//*/
System.out.println("Applet initialized");
}
public void start() {
System.out.println("Applet starting");
BufferedImage[] imgArray = new BufferedImage[20];
/*
* load 20 copies of the image into the memory
*/
for(int i = 0; i < imgArray.length; i++) {
try {
URL imageUrl = new URL("http://www.raize.ch/Reisen/" +
"velo-eurasien/karten-rollover/" +
"western-tibet-highway_" +
"satellitenbild_grossplus.jpg");
InputStream in = imageUrl.openStream();
imgArray[i] = ImageIO.read(in);
in.close();
System.out.println("Image no. " + (i + 1) + " loaded!");
}
catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("All images loaded");
/*
* display the image inside the browser window
*/
this.setSize(imgArray[0].getWidth(), imgArray[0].getHeight());
this.getContentPane().add(new JLabel(new ImageIcon(imgArray[0])));
}
public void stop() {
System.out.println("Applet stopping");
}
public void destroy() {
System.out.println("Applet destroyed");
}
}
答案 0 :(得分:1)
如果只是因为拼写错误会更容易出现,请坚持initial-heap-size="256M" max-heap-size="1600M"
。
经过几次尝试后,我不知何故在四个不同的解决方案中盘旋并清除它工作的applet缓存(但仅限于32位WinXP机器上)。
这里重要的不是applet缓存,而是缓存的JNLP文件。转到Java控制面板,找到该应用程序。并在运行之间卸载它。