• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread doubt

 
Sushanta Chakrabarty
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting StackOverflowException when I run the following code.

Sushanta.

public class EE extends Thread{
EE e = new EE();
void q(){
synchronized(e){
try{
wait();
}
catch(Exception ex){}
}}
public static void main(String[]args){
EE e = new EE();
e.q();
}
}
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IN your main, you create an EE, your EE has a EE member that in turn has an EE
member which in turn has an EE member which repeats to infinity ... or in your case your stack overflows.

Basically one of your new EE's shouldn't be there at a guess remove the member variable one and make the method sync on instead.

PS in 'real' code wait should always be in a loop testing an appropriate variable.
 
ajay verma
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use super keyword in order to pass from super class
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your stack overflow derives somehow from havign two calls that look like this: EE e = new EE(); The rest is as given.

Most stack overflows descend somehow from this type of control-flow/logic-error mistake that looks like this.
[ March 30, 2008: Message edited by: Nicholas Jordan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic