Returning a large List from my EJB method throws StackOverflowError

In my Remote, I have the following method:

List<TransactRow> doTransactionIdSearch(String _tbTransactID)throws PetroException;

In my session scope JSF Backing Bean, I have the following call to the method:

@EJBprivate TransactionBrowserSessionRemote transactionBrowserSessionRemote;

LinkedList<TransactRow> results = (LinkedList<TransactRow>)

transactionBrowserSessionRemote.doTransactionIdSearch(this.getTransactID());

I am believing this is a List size issue, because when there are more than 1000 TransactRow type objects in the LinkList, I return the following error:

javax.servlet.ServletException: nested exception is: java.rmi.ServerError: Error occurred in server thread; nested exception is: java.lang.StackOverflowError

In Java EE, is there an issue of returning a large List from a EJB method back to a JSF managed bean or is just an issue of a large List?

Thanks,

--Todd

[1042 byte] By [jtp512a] at [2007-11-26 20:00:47]
# 1

With the following error message

javax.servlet.ServletException: nested exception is: java.rmi.ServerError: Error occurred in server thread; nested exception is: java.lang.StackOverflowError

I understood that

1) Garbage collector fail to work because there are reference to

the unused objects

2) your code is not freeing these unwanted objects

3) Hence these unwanted/unused object deposited on the stack

exceed the stack limit

What I suggest you to

1) Once you use an object Just dereference it with a null

assignment(make the object null) so that garbage collector

works on it and free the memory that is occupied by it and its

contents.

Object o=null;

If you want to see the stack just run this at command propmt to see the statistics

java -Xrunhprof or java -Xrunhprof <your class name>

u get a similar statistics like

SITES BEGIN (ordered by live bytes) Thu Mar 01 13:36:54 2007

percent livealloc'edstackclass

rankself accumbytes objsbytes objstracename

1 25.77% 25.77%61864 49161864491 300000 char[]

cvasu4a at 2007-7-9 22:58:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

javax.servlet.ServletException: nested exception is: java.rmi.ServerError: Error occurred in server thread; nested exception is: java.lang.StackOverflowError

Though I cant doubt , but the code might be going into INFINITE LOOP causing to java.lang.StackOverflowError. Even In that case , there are large amounts of unused/unwated objects deposited on the stack.

what ever the case

1)Object o=null;

2)check for infinite looping

Dont forget to allot the DUKES

3)increase the memory (finally as per your design requirements)

cvasu4a at 2007-7-9 22:58:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

cvasu4: Thanks for looking at this.

In my EJB, I have the following:

try {

DataSource ds = DataSourceManager.getInstance("jdbc/ThePool").getDataSource();

Connection con = null;

try {

con = ds.getConnection();

TransactFinder tfinder = new TransactFinder(con, _currentTransType, nBgnTime, nEndTime);

if (!_currentClientID.equals("0") && !StringUtils.isEmpty(_currentClientID)) {

tfinder.setClientKey(_currentClientID);

}

if (!StringUtils.isEmpty(_tbFilter)) {

tfinder.setFileFilter(_tbFilter);

}

this.transactionResultRows = tfinder.select();

if (this.transactionResultRows.size() <= 0) {

throw new PetroException("Empty Results.");

}

} catch (SQLException ex) {

ex.printStackTrace();

} catch (IOException ex) {

ex.printStackTrace();

} finally {

if (con != null) {

con.close();

}

}

} catch (SQLException ex) {

ex.printStackTrace();

}

}

return this.transactionResultRows;

At the return statement, I have the proper size List object - but from that snippet, I don't see where I would need to be nullifying any objects.

The call to my EJB is not in a loop as noted earlier.

When I return a small number of objects in the list. There isn't an issue, just when there is a large number, greater than a thousand objects in the list.

So, I am curious if returning a large list between a EJB and JSF managed bean is an issue.

Thanks,

--Todd

jtp512a at 2007-7-9 22:58:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

If I am not wrong then,from the below piece of line

this.transactionResultRows = tfinder.select();

the tfinder.select() is returning the desired list and transactionResultRown is your own defined list variable.

If my above understanding is correct then

why dont you put the nullifying object code in this block with a great caution

finally {

if (con != null) {

//nullify the list so the garbage collector run on this.

this.transactionResultRows=null;

con.close();

}

but let me know

1) this.transactionResultRows?

What is return type of this(I means the class where this code

snippet u put between try n catch)

2) Have your executed the command at command promt and

checked the contents of java.hprof.txt file in the same directory

java -Xrunhprof thiswhere this is the classname of the

code snippet

cvasu4a at 2007-7-9 22:58:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
dukes plealse
cvasu4a at 2007-7-9 22:58:42 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...