2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 By: Dave Cherkassky - dcherk Thread-safe connections 2006-03-18 06:48Posting here, since a post in 'Open Discussions' did not get a reply: We are trying to run a subreport within a report. However we are getting an exception thrown from the subreport code because it is trying to use the same java.sql.Connection as was passed into the report. Apparently the subreport is running on a different thread. Our implementation of java.sql.Connection detects that it is being used by 2 threads at the same time and throws an IllegalStateException. Questions: - do we have to have threadsafe Connection objects to run subreports? - what if the Connection is closed by the calling thread before the subreport is finished? Does the calling thread wait for all subreport threads? - does each subreport have it's own thread and do they run in parallel? - I assume that if Jasper Reports is using multiple threads it is doing thread pooling? How do we configure the pool? Thanks, Dave Cherkassky. By: Sanjeev Saha - sanjeevsaha RE: Thread-safe connections 2006-03-18 09:05What version of Jasper Reports are you using? Regards, Sanjeev By: Dave Cherkassky - dcherk RE: Thread-safe connections 2006-03-18 12:11The latest stable release (I think its 1.2.0) -- I just downloaded it 3 days ago. Thanks, Dave Cherkassky By: Lucian Chirita - lucianc RE: Thread-safe connections 2006-03-20 01:36Usually subreports use the same connection as the master to run queries. However, this is not imposed in any way and one is able set any connection as connectionExpression for the subreport. Therefore, if your connections cannot be used by several thread simultaneously, you can pass a separate connection to be used by the subreports. To answer the rest of your questions: - the master report would not close the connection before the subreports finish (see the next point) - each subreport has its own thread. They never run in parallel, not even with the master. When a subreport needs to be filled, the parent thread launches a thread for the subreport and then waits for it to finish until resuming its own filling process. Subreport threads are mainly used to manage a call stack. - no thread pooling is done, a new thread gets created for each subreport. Regards, Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now