db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From derbyfan195 <huang...@gmail.com>
Subject Re: Does using DerbyDB require synchronization?
Date Tue, 09 Sep 2008 13:40:35 GMT


Thanks for your response. I'm more interested in not having to establish
separate connections for each thread as I've noticed establishing connection
in Derby takes a while, so if I can use the same connection among the
different threads (with some synchronization), that would be the ideal case
for me at the moment. 

What puzzles me is that you said when you close a ResultSet on a connection,
all other ResultSets lose their position. My understanding is that from a
Connection, you get a Statement, and from a Statement, you get a ResultSet.
Having multiple ResultSet from the same Statement is troublesome, but I
thought ResultSets from different Statements should never have conflict with
each other, i.e., if I close a ResultSet on Statement A, it shouldn't affect
another ResultSet that's opened on Statement B. Is this understanding not

Looking forward to your reply. Thanks!


Knut Anders Hatlen wrote:
> derbyfan195 <huang195@gmail.com> writes:
>> Just started using Derby in my Java code and realized some weird
>> synchronization issues. I have multiple threads accessing the same Derby
>> Database (embedded one) through a single connection. They issue read-only
>> queries, i.e., select, each with its own statement, and does some
>> operations
>> on the returned ResultSet using ResultSet.next() operation. However, I
>> noticed sometimes, one of these next() calls would fail and gave me an
>> error
>> of next() is not permitted, make sure that AUTO_COMMIT is turned OFF. I
>> don't know what this error means or why I need to turn AUTO_COMMIT off.
>> Do I
>> need any synchronization among the statement objects obtained from the
>> same
>> connection object? Any help would be appreciated.
> Hi,
> You can turn auto-commit off by calling conn.setAutoCommit(false). The
> reason why it may help, is that with auto-commit on, the transaction
> (Connection) is committed automatically each time a ResultSet is closed,
> and when the transaction is committed, all ResultSets in that connection
> lose their positions (and, depending on the holdability setting, they
> may be closed).
> That said, whereas using the same connection concurrently from different
> threads should work, I would recommend that you have a separate
> connection for each thread. That would give you fewer problems with the
> different threads changing the transaction state for each other, and it
> could improve the performance since Derby could then execute more
> queries in parallel.
> -- 
> Knut Anders

View this message in context: http://www.nabble.com/Does-using-DerbyDB-require-synchronization--tp19379460p19392670.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

View raw message