Home arrow static arrow Java Programming [Archive] - Stack Overflow Error
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Stack Overflow Error
This topic has 62 replies on 5 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | Next »

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 12:16 PM (reply 30 of 62)



 
This wouldn't cause a stack overflow. All it would
cause is the stack not to be garbage collected (I
think). As I said, this is just a sidenote. Look at
your stacktrace and you will see that there is a cycle
in it. I

I don't see any cycle, though I may not know how to look. I followed the app for about 10 minutes, getting stack traces every minute or so. There were always exactly the same number of threads as I would have expected to be alive. The old ones were all dying in due time. At most stages of the app, the stack trace looked like the one below. It would return to looking like this again and again.

Sorry if I havn't been too detailed with the code, but there's alot of it and I didn't want to overwhelm anyone. Is there any specific portion that would help you give me more detailed advice?

Thanks for your help,
John


"Thread-174" prio=5 tid=0x00a25a50 nid=0x804 waiting on condition [316f000..316f
d94]
at java.lang.Thread.sleep(Native Method)
at GameOverObserver.run(Mediator.java:345)
at java.lang.Thread.run(Thread.java:534)

"Thread-173" prio=5 tid=0x00a21410 nid=0x59c waiting on condition [32af000..32af
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-171" prio=5 tid=0x00a1f408 nid=0x430 waiting on condition [356f000..356f
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-169" prio=5 tid=0x00a27500 nid=0x724 waiting on condition [33af000..33af
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-167" prio=5 tid=0x00a2a1f0 nid=0xd8 waiting on condition [322f000..322fd
94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-165" prio=5 tid=0x00a125a8 nid=0xec waiting on condition [34af000..34afd
94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-163" prio=5 tid=0x00a27158 nid=0x550 waiting on condition [31ef000..31ef
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-161" prio=5 tid=0x00a22e60 nid=0xf98 waiting on condition [352f000..352f
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-159" prio=5 tid=0x00a24428 nid=0xe18 waiting on condition [346f000..346f
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Thread-157" prio=5 tid=0x00a24588 nid=0x9b0 waiting on condition [332f000..332f
d94]
at java.lang.Thread.sleep(Native Method)
at ActionObserver.run(Mediator.java:494)
at java.lang.Thread.run(Thread.java:534)

"Signal Dispatcher" daemon prio=10 tid=0x009f8f68 nid=0x670 waiting on condition
[0..0]

"Finalizer" daemon prio=9 tid=0x009c0bf8 nid=0x9d0 in Object.wait() [2b5f000..2b
5fd94]
at java.lang.Object.wait(Native Method)
- waiting on <0x10010498> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <0x10010498> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x009bf7c8 nid=0xea0 in Object.wait() [2b
1f000..2b1fd94]
at java.lang.Object.wait(Native Method)
- waiting on <0x10010388> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:429)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
- locked <0x10010388> (a java.lang.ref.Reference$Lock)

"main" prio=5 tid=0x00034e88 nid=0xee8 waiting on condition [7f000..7fc3c]
at java.lang.Thread.sleep(Native Method)
at Mediator.<init>(Mediator.java:238)
at Ocr.main(Ocr.java:73)
"VM Thread" prio=5 tid=0x009f76f8 nid=0xaec runnable

"VM Periodic Task Thread" prio=10 tid=0x009fb780 nid=0xbdc waiting on condition

"Suspend Checker Thread" prio=10 tid=0x009f8620 nid=0xbd4 runnable

 

Posts:18,384
Registered: 21.03.00
Re: Stack Overflow Error  
Aug 7, 2004 12:23 PM (reply 31 of 62)



 
Hi,

Post the stack trace that you get when you get the Stack overflow error. It says it all. That's the only thing you need to show us.

/Kaj
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 12:34 PM (reply 32 of 62)



 
I don't see any cycle, though I may not know how
to look. I followed the app for about 10 minutes,
getting stack traces every minute or so........

That's not a stack trace, that's a thread dump.
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 12:34 PM (reply 33 of 62)



 
Oh yeah, don't post the whole thing, just a couple of cycles.
 

Posts:18,384
Registered: 21.03.00
Re: Stack Overflow Error  
Aug 7, 2004 12:38 PM (reply 34 of 62)



 
And take it from the top of the trace.

/Kaj
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 12:44 PM (reply 35 of 62)



 
Wait a second. WTF am I doing???

I'm helping you debug a design I think is basically flawed. I still think that using the same Runnable object for several threads is basically a bad idea unless you have some really good reason for doing this. You are going to have to convince me that you understand what you are doing before I spend time debugging a threading problem.
 

Posts:18,384
Registered: 21.03.00
Re: Stack Overflow Error  
Aug 7, 2004 12:54 PM (reply 36 of 62)



 
I'm helping you debug a design I think is basically
flawed. I still think that using the same Runnable
object for several threads is basically a bad idea
unless you have some really good reason for
doing this. You are going to have to convince me that
you understand what you are doing before I spend time
debugging a threading problem.

Well, then I also have to add my 5 cents. Why do you use so many short lived threads? That is bad design. Creation of threads is expensive. Re-use them, or let them live, and don't spawn lots and lots of threads.

/Kaj
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 1:22 PM (reply 37 of 62)



 
I'm helping you debug a design I think is basically
flawed. I still think that using the same Runnable
object for several threads is basically a bad idea
unless you have some really good reason for
doing this. You are going to have to convince me that
you understand what you are doing before I spend time
debugging a threading problem.

Like I said, the object is only a wrapper. I actually don't think it's a bad design, but please tell me what you think. As an example, I have a GameOverObserver class, one of whose member variables, mThread, holds a Thread object (please see the very first post for the start() method of the GameOverObserver class). When the app starts, this GameOverObserver also starts. It watches until it detects a GameOverEvent. When it does, it sends this event to my EventManager class, after which it dies. The EventManager class handles the GameOverEvent by starting up some other observers which watch and track events in the new game. When the new game has reached a certain point of action, another event will be triggered which calls start() on the GameOverObserver, so we know when this new game ends. Once again the start() method is called, and GameOverObserver.mThread is set to a new thread.

Thus multiple threads GameOver threads are never running at the same time, so I see no danger. But perhaps you still do?

Thanks for additional thoughts,
Johh
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 1:25 PM (reply 38 of 62)



 
That's not a stack trace, that's a thread dump.

I got it by pressing <ctrl>-<break> in windows, which is supposedly a stack trace. i was confused by this too. Anyway, I'm trying to reproduce the error and catch the throwable, but it just ran for 40 mins without problems....

 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 1:29 PM (reply 39 of 62)



 
Unless you're smothering the exception, e.g.
catch (Throwable th) {    // do nothing } 
you'll get the stack trace on the consol when you get the StackOverflowError.
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 1:32 PM (reply 40 of 62)



 
Unless you're smothering the exception, e.g.
catch (Throwable th) {// do nothing} 
you'll get the stack trace on the consol
when you get the StackOverflowError.

Yeah, I know. I'm not smothering it. It's just that since I added the try/catch code, I havn't yet reproduced the error.... It's running as I type...

John
 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 1:39 PM (reply 41 of 62)



 
Ah, yes, that old trick, perpetrated by bugs through the ages--hide when the print statements or debugger show up. I think they learned it from Schroedinger's cat.
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 1:42 PM (reply 42 of 62)



 
.........<snip>
When the new game has reached a certain
point of action, another event will be triggered
which calls start() on the GameOverObserver
.........<snip>
Thus multiple threads GameOver threads are never
running at the same time, so I see no danger.
But perhaps you still do?
.........<snip>

I can't see your code, so my only comment can be 'if you say so'. But, you might consider what happens if two 'certain point of action' events come close enough together that the new thread starts before the old thread is finished.

My point is that I have never seen this done before. I might expect this kind of code some kind of a distributed graphics analysis package where object creation overhead can't be allowed to slow the calculation or communication between threads, but I would suspect that even then the programmer would start out using threads in the normal way and when he ran into a performance bottleneck and figured out that it was the creation of thread objects which was causing the problems, he decided to reuse the old objects instad of creating new ones. Kind of like a 'thread pool'. You don't seem to have anything like this. What is your thinking in reusing these Runnable objects????
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 1:51 PM (reply 43 of 62)



 
Ah, yes, that old trick, perpetrated by bugs through
the ages--hide when the print statements or debugger
show up. I think they learned it from Schroedinger's
cat.

What old trick are you referring to? I can't tell which post this is a reply to.

Thanks
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 1:55 PM (reply 44 of 62)



 
I can't see your code, so my only comment can be 'if
you say so'. But, you might consider what happens if
two 'certain point of action' events come close enough
together that the new thread starts before the old
thread is finished.

I have checks to ensure this.

What is your thinking in reusing these
Runnable objects????

I actually thought it was clean, though I don't have that much experience with Java threads and wasn't aware of the significant overhead involved in creating new ones. I suppose instead of letting the thread die and creating a new one, I could call wait() and notify(). Do you consider that a better alternative?

By the way, thanks very much for your help. I'm learning alot.

John
 
This topic has 62 replies on 5 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | Next »