本文介绍了java.lang.OutOfMemoryError:Java堆空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在玩一些来自Oracle网站的Collections的例子
I was playing with some examples of Collections from Oracle website
public class Timing {
public static void method(){
List numbers = new ArrayList();
for (double i = 1; i <= Double.MAX_VALUE; i++)
numbers.add(new Double(i));
Collections.shuffle(numbers);
List winningcombination = numbers.subList(0, 10);
Collections.sort(winningcombination);
}
public static void main(String[] args)
{
long start = System.currentTimeMillis();
method();
long end = System.currentTimeMillis();
System.out.println("time elapsed : " + (end-start));
}
}
我尝试看看需要多长时间它为Double.MAX_VALUE。我有这个:
I tried to see how long it will take to do it for Double.MAX_VALUE. And I got this :
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
我有办法解决这个问题吗?
I there a way to fix this ?
推荐答案
Collection
?不,地球上没有那么多的RAM。 Double.MAX_VALUE
约为2倍的10到308次幂:那是2,后面是300多个零。给予百思买一个电话,看看他们会收取多少钱在你的电脑。
Is there a way to allow you to create and store Double.MAX_VALUE
objects in a Collection
? No. There's not that much RAM on Earth. Double.MAX_VALUE
is about 2 times ten to the 308th power: that's 2 followed by over 300 zeros. Give Best Buy a call, see how much they'd charge to put that in your computer.
这篇关于java.lang.OutOfMemoryError:Java堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!