ejb@glassfish.java.net

RE: RE: Re: Returning a List from a Stateless EJB throws aStackOverflowError

From: Ken Cavanaugh <Ken.Cavanaugh_at_Sun.COM>
Date: Fri, 02 Mar 2007 11:30:40 -0800

On Fri, 2007-03-02 at 13:06 -0600, Todd Patrick wrote:

> Ken:
>
> It is a Linked List.
>
> I am running the following:
>
> Sun Java System Application Server Platform Edition 9.0_01 (build b14)
> Java(TM) SE Runtime Environment (build 1.6.0-b105)
> JSF 1.2_03
>
> Below is the method that builds the Linked List.
>
> Thank you for your time to look at this.
>
> Is it an issue to be using a Linked List?
>

Yes. The problem is that the fast reflective object copier needs to
traverse the entire
object graph in order to copy it, and this is necessarily recursive
(obviously I could
simulate the recursion, but it's easier just to recurse in the copier).
I think changing
from LinkedList to ArrayList will probably fix this problem, and is most
likely more
efficient as well. An ArrayList just allocates (and re-allocates) a
backing array as needed,
while the LinkedList is allocating lots of LinkedList.Entry nodes for
the next and prev
pointers. An ArrayList is usually a better choice. It is also helpful
if you have some
idea of the size of the results to pass the size in the ArrayList
constructor.

Ken.