[英]OutOfMemoryException (after upgrade to JDK 7u45)
After upgrading to the latest JDK, we've got (on some machines) a strange OutOfMemoryException
. 在升级到最新的JDK之后,我们(在某些机器上)有一个奇怪的
OutOfMemoryException
。
Consider this simple application: 考虑这个简单的应用:
public class Test
{
public static void main (String[] args) {
try {
java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat("E dd/MM/yyyy HH:mm");
System.out.println("formatted date: " + dateFormatter.format(new java.util.Date()));
} catch (Exception x) {
System.err.println(x);
System.exit(1);
}
}
}
Running this small program will result in this exception (even when running it with -Xmx2048M -Xms2048
): 运行这个小程序将导致此异常(即使使用
-Xmx2048M -Xms2048
运行它):
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Currency.readLongArray(Currency.java:657)
at java.util.Currency.access$100(Currency.java:76)
at java.util.Currency$1.run(Currency.java:211)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.Currency.<clinit>(Currency.java:192)
at java.text.DecimalFormatSymbols.initialize(DecimalFormatSymbols.java:566)
at java.text.DecimalFormatSymbols.<init>(DecimalFormatSymbols.java:94)
at java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:157)
at java.text.NumberFormat.getInstance(NumberFormat.java:767)
at java.text.NumberFormat.getIntegerInstance(NumberFormat.java:439)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:664)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:585)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:560)
at Test.main(Test.java:5)
Could someone please explain this to me? 有人可以向我解释一下吗?
The java version we are using is: 我们使用的java版本是:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
When we are using a prior version, we have no problem: 当我们使用以前的版本时,我们没有问题:
java -version java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
java Test java测试
formatted date: ma 21/10/2013 10:19
Update: Before everyone is mentioning increasing the heap size... I already tried it: 更新:在每个人都提到增加堆大小之前...我已经尝试过了:
java -Xmx2048M -Xms2048M Test java -Xmx2048M -Xms2048M测试
Runtime.getRuntime().freeMemory(): 2048120480
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Currency.readLongArray(Currency.java:657)
at java.util.Currency.access$100(Currency.java:76)
at java.util.Currency$1.run(Currency.java:211)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.Currency.<clinit>(Currency.java:192)
at java.text.DecimalFormatSymbols.initialize(DecimalFormatSymbols.java:566)
at java.text.DecimalFormatSymbols.<init>(DecimalFormatSymbols.java:94)
at java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:157)
at java.text.NumberFormat.getInstance(NumberFormat.java:767)
at java.text.NumberFormat.getIntegerInstance(NumberFormat.java:439)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:664)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:585)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:560)
at Test.main(Test.java:8)
I dug into the code of java.util.Currency
. 我挖掘了
java.util.Currency
的代码。 It reads in a resource file located in the Java JRE, in the static Class initializer block. 它在静态类初始化程序块中读入位于Java JRE中的资源文件。
String homeDir = System.getProperty("java.home");
try {
String dataFile = homeDir + File.separator +
"lib" + File.separator + "currency.data";
DataInputStream dis = new DataInputStream(
new BufferedInputStream(
new FileInputStream(dataFile)));
if (dis.readInt() != MAGIC_NUMBER) {
throw new InternalError("Currency data is possibly corrupted");
}
formatVersion = dis.readInt();
if (formatVersion != VALID_FORMAT_VERSION) {
throw new InternalError("Currency data format is incorrect");
}
dataVersion = dis.readInt();
mainTable = readIntArray(dis, A_TO_Z * A_TO_Z);
int scCount = dis.readInt();
scCutOverTimes = readLongArray(dis, scCount);
As you can see, it reads in JRE/lib/currency.data . 如您所见,它读入JRE / lib / currency.data 。 The fourth integer contains the
scCount
. 第四个整数包含
scCount
。 This integer will be too high. 这个整数太高了。 I guess that that file is corrupt.
我猜那个文件已损坏了。 Try replacing it.
尝试更换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.