看一下下面這段程序
package com.xcblcx.test;

import java.util.ArrayList;

public class ThreadNotifyTest {
private ArrayList list = new ArrayList();

/**
* @param args
*/
public static void main(String[] args) {
ThreadNotifyTest test = new ThreadNotifyTest();
Queue queue = test.new Queue();
try{
Thread.sleep(1000);
for(int i=0;i<5;i++) {
queue.addStr(new Integer(i).toString());
Thread.sleep(1000);
}
}catch(Exception e) {
e.printStackTrace();
}
}
class ThreadTest extends Thread {
Queue queue = new Queue();
public ThreadTest() {
//this.queue = queue;
}
public void run() {
while(true) {
try{
System.out.println("Thread start
.");
String testStr = this.queue.getNext();
System.out.println(testStr);
}catch(Exception e ){
e.printStackTrace();
}
}
}
}
class Queue {
private ThreadTest threadTest = null;
public Queue(){
//this.threadTest = new ThreadTest(this);
this.threadTest = new ThreadTest();
this.threadTest.start();
}
public void addStr(String str) {
synchronized(list) {
list.add(str);
list.notify();
}
}
public String getNext() throws InterruptedException {
synchronized(list) {
while(list.size() <= 0) {
System.out.println("wait start");
list.wait();
System.out.println("wait end");
}
return (String)list.remove(0);
}
}
}

}
運行結(jié)果為:
java.lang.StackOverflowError
Exception in thread "main"
請問為什么?











































































運行結(jié)果為:
java.lang.StackOverflowError
Exception in thread "main"
請問為什么?