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:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 11:26 AM (reply 15 of 62)



 
Is the above being called from inside a
Thread/Runnable's run() method? If so, that's
recursion--that run() method will never end, and more
and more will just get piled on top of it.

Actually, I think I'm wrong there--the run() method will end. However, since the thread that was running that run method is now the parent thread of the newly created thread, I think the original thread must still survive in some miminal form. That might be why it's taking a long time and a lot of threads before you see the meltdown.
 

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



 
Is this code from your first post
publicsynchronized void start() {...} 
in a class
that implements Runnable or that extends Thread?

It implements Runnable. That start() method has nothing to do with Thread's start() method. Perhaps poorly named on my part...

Is the above being called from inside a
Thread/Runnable's run() method? If so, that's
recursion--that run() method will never end, and more
and more will just get piled on top of it.

Not that I can see so far. When I create new Threads, the old Threads die.

John
 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 11:32 AM (reply 17 of 62)



 
It implements Runnable. That start() method has
nothing to do with Thread's start() method. Perhaps
poorly named on my part...

Nah, I think it's reasonable. I do the same thing sometimes. Just couldn't tell without the context.


Is the above being called from inside a
Thread/Runnable's run() method? If so, that's
recursion--that run() method will never end, and
more
and more will just get piled on top of it.

Not that I can see so far. When I create new Threads,
the old Threads die.

Yes, but are you creating all the new threads from the same parent thread or are they being created inside the run method (or something called by the run method) of the previous thread?
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 11:33 AM (reply 18 of 62)



 
However, since the thread that was running
that run method is now the parent thread of the newly
created thread, I think the original thread must still
survive in some miminal form. That might be why it's
taking a long time and a lot of threads before you see
the meltdown.

If that's so, that could definitely be it. But why should the parent thread be surviving. I have my program's main thread surviving (in a loop which sleeps and does nothing), but why should parent threads always survive?

And if they do, I would ask: How could you properly create any program that created and destroyed many threads?

John
 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 11:34 AM (reply 19 of 62)



 
If you can't find it, strip your code down to the mininum that reproduces the problem and post it here.

Of course, if you' able to do that, you'll quite likely find the source of the problem yourself. :-)
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 11:35 AM (reply 20 of 62)



 
Yes, but are you creating all the new threads from the
same parent thread or are they being created inside
the run method (or something called by the run method)
of the previous thread?

They certainly are not being created by the same parent thread. So if that's a problem, I have to rethink my design completely.

Parent thread creates children... the children have children and then die... and so on down the generations. That would be the description of how my app is working.

 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 11:37 AM (reply 21 of 62)



 
Just a sidenote. Using the same Runnable object for multiple threads seems convoluted.
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 11:41 AM (reply 22 of 62)



 
Just a sidenote. Using the same Runnable object for
multiple threads seems convoluted.

Why is that?
 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 11:43 AM (reply 23 of 62)



 
If that's so, that could definitely be it. But why
should the parent thread be surviving. I have my
program's main thread surviving (in a loop which
sleeps and does nothing), but why should parent
threads always survive?

And if they do, I would ask: How could you properly
create any program that created and destroyed many
threads?

If one thread creates and destroys thousands of other threads, no biggie. But if a T1 creates T2 and then T1 dies, and T2 creates T3 and then T2 dies, and then T3 creates T4 and so on... I think the VM keeps some internal reference to which thread created which. I'm not really sure, but that seems consistent with the behavior your seeing.

Or I might just be taling outta my butt.
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 11:46 AM (reply 24 of 62)



 
The exact same code with the exact same variables is going to be executed by multiple threads. Inside of your run method, you can't count on which variable got updated by which thread. It seems like you would have to syncronize all the variables. It really is going to depend on what your application does, but it seems like a complication which would be better left out unless the was a **** good reason.
 

Posts:37,103
Registered: 3/30/99
Re: Stack Overflow Error  
Aug 7, 2004 11:46 AM (reply 25 of 62)



 
Yes, but are you creating all the new threads from
the
same parent thread or are they being created inside
the run method (or something called by the run
method)
of the previous thread?

They certainly are not being created by the same
parent thread. So if that's a problem, I have to
rethink my design completely.

Parent thread creates children... the children have
children and then die... and so on down the
generations. That would be the description of how my
app is working.


I'm not sure if it is a problem. At first I thought it would be, but I'm not sure.
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 11:47 AM (reply 26 of 62)



 
I think the VM keeps some internal reference...

ThreadGroup keeps a reference.
 

Posts:340
Registered: 7/8/04
Re: Stack Overflow Error  
Aug 7, 2004 11:51 AM (reply 27 of 62)



 
I think the VM keeps some internal reference...

ThreadGroup keeps a reference.

bbritta,

Can you confirm for sure that this would cause a stack overflow? That would pinpoint my problem. Your other concern about multiple threads on the same object is not a concern here, b/c only one thread uses it at a time. Think of the object as a shell, and the threads as snails... when one dies, a new one can crawl in....

John
 

Posts:8,813
Registered: 10/4/00
Re: Stack Overflow Error  
Aug 7, 2004 12:00 PM (reply 28 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. It's going to repeat every so often. You can get huge clues from that. You haven't posted enough of the code you are actually having the problem with for me to figure out where the problem lies.
 

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



 
Yeah, I think I was off-base with my earlier comments about chaining threads. I still don't think it's a great design, but it doesn't seem like it would lead to stack overflow. Sorry for the red herring.
 
This topic has 62 replies on 5 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | Next »