Subject RE: [Firebird-Java] Re: Should (Could) FBStatements be held in WeakHashMap
Author Nickolay Samofatov
Hello, Roman

>> AFAIK, all JDBC APIs are required to be thread-safe by the spec.
>> Jaybird breaks the spec here. This is not a big problem, in fact.

>No, it's not. You can check the specification. There's nothing about
>thread safety. JayBird does not allow multiple threads work on the
>same connection (and this is a nature of all JTA-enabled
>applications - transaction is associated with a thread, see specs),
>but you can happily use connection per thread scheme.

This part of JDBC spec is very clear. Here is a snippet:
------------
9.2 Multi-threading
We require that all operations on all the java.sql objects be
multi-thread safe and able to cope correctly with having several
threads simultaneously calling the same object.

Some drivers may allow more concurrent execution than others.
Developers can assume fully concurrent execution; if the driver requires
some form of synchronization, it will provide it. The only difference
visible to the developer will be that applications will run with reduced
concurrency.

For example, two Statements on the same Connection can be executed
concurrently
and their ResultSets can be processed concurrently (from the perspective of
the
developer). Some drivers will provide this full concurrency. Others may
execute
one statement and wait until it completes before sending the next.

One specific use of multi-threading is to cancel a long running statement.
This is done by using one thread to execute the statement and another to
cancel
it with its Statement.cancel() method.

In practice we expect that most of the JDBC objects will only be accessed
in a single threaded way. However some multi-thread support is necessary,
and our attempts in previous drafts to specify some classes as MT safe and
some as MT unsafe appeared to be adding more confusion than light.
-------------

Nickolay Samofatov