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(); } }
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.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
ajay verma
Ranch Hand
Joined: Dec 10, 2007
Posts: 37
posted
0
you should use super keyword in order to pass from super class
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
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 ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."