Subject Fwd: Re: Problem with multi-threaded update/query causing JDBC driver errors
Author Fabiano
Hi,

Basically, you can´t share a single connection between many threads. Make sure each thread get the connection, use it, close it and return to the pool (if there is a pool).

Even now that firebird client is threadsafe, you should use the procedure described above, to avoid waiting for client synchronization.

Remember also that you can´t open two resultsets at the same time using the same JDBC connection. It causes the errors you are describing. I think it´s related to JDBC specification, not to Jaybird implementation.

If you want to open many resultsets at the same time using just one connection, take a look at CachedRowSet interface and default implementation (rowset.jar, you can download it somewhere).

Regards,

Fabiano

--- In Firebird-Java@yahoogroups.com, Roman Rokytskyy <roman@...> wrote:
>
> Hi Phil,
>
> Sorry to bring this topic up.
> This is the exact issue we are having currently. The error messages is
> very similar.
> We are running 2 connection pools in 2 different app server connecting
> to 1 FB.
>
> Appreciate if you could post your notes on this if possible (since it's
> already >3 years old =) )
>
> Thanks,
> John
>
> --- In Firebird-Java@yahoogroups.com, "phil_hhn" <time_lord@> wrote:
> >
> > (This call being raised as suggested by Roman in the main FB support
> > NG...)
> >
> > We had some multi-threaded code running where both threads were using
> > the same JDBC connection; if they ran SQL code at the same time,
> > errors could occur. (The threads have since been changed to have their
> > own JDBC connections.)
> > Sometimes the error was a NullPointerException, or in some cases "GDS
> > Exception. 335544332. invalid transaction handle (expecting explicit
> > transaction start)".
> >
> > I created a test case to mimic the situation but could not reproduce
> > the error (so no sample code, sorry). However I have captured some of
> > the stack traces (from our main application), as below. (Sometimes I'd
> > have to run the code several times before the timing of the threads
> > clashed and an error would occur.)
> > We are using Firebird 1.5.3 (4870), JDBC driver 2.1.1.
> >
> > Most common error:
> > =================================
> > org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544332. invalid
> > transaction handle (expecting explicit transaction start)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.executeQuery(AbstractStatement.java:228)
> > << Our code, running a query >>
> >
> >
> > More worrying is this one:
> > =================================
> > java.lang.NullPointerException
> > at
> > org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlExecute2(AbstractJavaGDSImpl.java:1119)
> > at
> > org.firebirdsql.gds.impl.GDSHelper.executeStatement(GDSHelper.java:224)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.internalExecute(AbstractStatement.java:1109)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.executeQuery(AbstractStatement.java:219)
> > << Our code, running a query >>
> >
> > Followed immediately by:
> > =================================
> > org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544726. Error
> > reading data from the connection.
> > null
> > Reason: Error reading data from the connection.
> > null
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.ensureTransaction(InternalTransactionCoordinator.java:313)
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.executionStarted(InternalTransactionCoordinator.java:342)
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator.executionStarted(InternalTransactionCoordinator.java:38)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.notifyStatementStarted(AbstractStatement.java:243)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.notifyStatementStarted(AbstractStatement.java:234)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.executeQuery(AbstractStatement.java:216)
> >
> > ... all subsequent queries resulted in the following (obviously
> > Firebird had crashed, and I verified this by checking the windows
> > event log which had an entry for "fbserver.exe: terminated abnormally"):
> > =================================
> > org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544721. Unable
> > to complete network request to host "".
> > Reason: Unable to complete network request to host "".
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.ensureTransaction(InternalTransactionCoordinator.java:313)
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.executionStarted(InternalTransactionCoordinator.java:342)
> > at
> > org.firebirdsql.jdbc.InternalTransactionCoordinator.executionStarted(InternalTransactionCoordinator.java:38)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.notifyStatementStarted(AbstractStatement.java:243)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.notifyStatementStarted(AbstractStatement.java:234)
> > at
> > org.firebirdsql.jdbc.AbstractStatement.executeQuery(AbstractStatement.java:216)
> > << Our code, running a query >>
> >
> >
> > Hope this helps. Let me know if you want any other details.
> > Thanks, Phil
> >
>