out of memory吧,jvm资源耗尽就会报出Exception了
解决方案 »
- 鼠标点击按钮时添加按键声音
- 什么时候该用TYPE_SCROLL_INSENSITIVE 什么时候该用TYPE_SCROLL_SENSITIVE
- 我用exe4j生成了exe文件后,运行时报错是什么原因?
- xml 文件(DTD)中能否有重名的Element?
- JIT哪位大哥能为我好好解释一下这东西
- java调用c的动态链接库的问题!已经郁闷一天了!在线等待 急!
- 哪里有Vsiual J++6.0下载?在线等
- 关于jbuilder中的链接问题(急用,在此先谢过各位)
- 请各位大仙多多指点
- 来个大神指点下我该怎么添加
- /** 急呀,鼠标事件的一个小问题 */
- **** 怎么实现多继承?散分中…… ****
at sun.io.CharToByteConverter.convertAny(CharToByteConverter.java:139)
at sun.nio.cs.StreamEncoder$ConverterSE.implWrite(StreamEncoder.java:208)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:134)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:191)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
at java.io.PrintStream.newLine(PrintStream.java:323)
at java.io.PrintStream.println(PrintStream.java:516)
at Container.say(Test1.java:42)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
.
.
.
.
.
.
.
..
我试了java -Xmx 没有用的。
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
满满一屏
对堆栈要求太大了
以下是同样问题在forum.java.sun.com上帖上后得到的回复。
共同学习。
========================
Exception in thread "main" java.lang.StackOverflowError
Author: tomxujack Dec 19, 2002 9:04 PM
When I run the java application below,it always throw a exception as:
how can I run it over completely or more?------------- exception -----------------------------------------
Exception in thread "main" java.lang.StackOverflowError
at sun.io.CharToByteConverter.convertAny(CharToByteConverter.java:139)
at sun.nio.cs.StreamEncoder$ConverterSE.implWrite(StreamEncoder.java:208)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:134)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:191)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
at java.io.PrintStream.newLine(PrintStream.java:323)
at java.io.PrintStream.println(PrintStream.java:516)
at Container.say(Test1.java:42)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
at Container.say(Test1.java:45)
----------------------------------------------------------
.
.
.--------------------- source code -----------------------
public class Test1{/*public void say(int i){
System.out.println(i);
if((++i)<350000)
say((++i));
}
public static void main(String s[]){
Test1 t = new Test1();
t.say(0);
}
*/
public static void main(String s[]){Container m = new Container(0);
Container ma = m;for(int i=1;i<1000000;i++){
Container c = new Container(i);
if(m != null){
m.setSon(c);
}
m = c;
}
ma.say();
}}class Container{
int id;
Container son;
public Container(int id){
this.id = id;
}
public void say(){System.out.println(id);if(son != null){
son.say();
}
}
public void setSon(Container son){
this.son = son;
}
}
Re: Exception in thread "main" java.lang.StackOverflowError
Author: jarreth
In Reply To: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:06 PM Reply 1 of 10
why do you need 1000000 components?
Re: Exception in thread "main" java.lang.StackOverflowError
Author: tomxujack
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:16 PM Reply 2 of 10
I only want to know how many times recursion can do.I think it relative with JVM heap setting.
but I have set > java -Xmx256000000 .............
no use.And on different computer,different OS.result is different.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: paulcw
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:33 PM Reply 3 of 10
Wait a minute. You've written a program that deliberately tries to overflow the stack. And you get a stack overflow error. Of course.> And on different computer,different OS.result is different.Of course.
What's the problem exactly?Are you asking how you can make an infinitely large stack?Can't be done. Computers are discrete finite math engines.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: JN_
In Reply To: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:46 PM Reply 4 of 10
> When I run the java application below,it always throw
> a exception as:
> how can I run it over completely or more?Stop designing it to intentionally crash.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: tomxujack
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:51 PM Reply 5 of 10
In a application.I must use recursion to deal with a large object.
I want to know,how many times JVM allow the recursion do?
1000 times?
10000 times?
100000 times?
How can I make sure it?
Re: Exception in thread "main" java.lang.StackOverflowError
Author: jarreth
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:59 PM Reply 6 of 10
print out an incremented number on every recursion entrywhen it blows up, the last number printed is the number of times.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: JN_
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 9:59 PM Reply 7 of 10
> In a application.I must use recursion to deal with a
> large object.
> I want to know,how many times JVM allow the recursion
> do?
> 1000 times?
> 10000 times?
> 100000 times?
> How can I make sure it?You can't.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: tomxujack
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 10:08 PM Reply 8 of 10
But the application is going to run in many different OS,such as window,solair,linux,hareware is quit different.
I know should control the recursion times.
But how cano I do?
Help!
Re: Exception in thread "main" java.lang.StackOverflowError
Author: JN_
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 10:11 PM Reply 9 of 10
Find a way that doesn't require recursion.
Re: Exception in thread "main" java.lang.StackOverflowError
Author: paulcw
In Reply To: Re: Exception in thread "main" java.lang.StackOverflowError Dec 19, 2002 11:02 PM Reply 10 of 10
If stack overflow errors are a likely possibility in your design, then change your design.Really. Trying to hover just below the maximum is just asking for trouble.And anyway, I don't think this question can be answered. The number of stack frames you can get away with depends on the size of the stack frame, which I believe changes per-method. So even if you ran a test that gave you an answer, in production the actual method you use will have different results.And I wouldn't be surprised if the stack frame was also dependant on any native methods called (although I don't know if that actually is an issue or not). So you may not be able to get an answer across OS's.