google-code-export / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

JaQu concurrency patch #298

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is a small patch which includes two changes for concurrency.

1. Synchronizing classMap in Db for sharing instances of Db concurrently.

2. Allow an alias singleton to be used concurrently.  Basically instantiate 
null mapped fields within the alias once.  In the following example, u gets 
mapped once on the first from() and then is safely re-used.

final Users u = new Users();
for (int i = 0; i < 1000; i++) {
 new Thread() {
   db.from(u).select();
 }.start();
}

Original issue reported on code.google.com by James.Mo...@gmail.com on 8 Mar 2011 at 2:30

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks a lot! The patch looks good, however I want to test it first. I'm sorry 
about the delay...

Original comment by thomas.t...@gmail.com on 9 Mar 2011 at 7:49

GoogleCodeExporter commented 9 years ago
Please run ./build.sh spellcheck

Please don't make Utils.COUNTER public, instead add a method
    public static long getNewObjectCounter() {
        return COUNTER.get();
    }

Please run ./build.sh docs (there is a method with wrong identation)

Please add ConcurrencyTest to TestAll

After this, please submit a new patch, I will then have a look again.

Original comment by thomas.t...@gmail.com on 26 Mar 2011 at 10:46

GoogleCodeExporter commented 9 years ago
I've revisited this patch since it was asked about on the group.

While my patch does solve the concurrent re-use of the table alias object as 
outlined in my first post it breaks Where functionality.  Specifically the few 
changes to TableDefinition are problematic because they solve one problem at 
the expense of creating other problems.

I still advocate the other simple changes in the patch which improve concurrent 
reuse of a Db instance:
1. Query.java: static *synchronized* <T> Query<T> from(Db db, T alias) {
2. Db.java: private final Map<Class<?>, TableDefinition<?>> classMap =
-        Utils.newHashMap();
+        Collections.synchronizedMap(new HashMap<Class<?>, 
TableDefinition<?>>());

I don't think its worthwhile to submit a revised patch file for those two 
changes.

Original comment by James.Mo...@gmail.com on 9 Jul 2011 at 3:27

GoogleCodeExporter commented 9 years ago

Original comment by thomas.t...@gmail.com on 22 Sep 2011 at 4:35