Hi,

My suggestion would be, try to do the heavy operations after opening the
database, if this is a problem for you.

There are multiple reasons why opening databases is synchronized, one is,
to avoid opening the same database multiple times concurrently. There are
cases where opening one databases causes opening another database (while it
is being opened).

Regards,
Thomas


On Wednesday, December 3, 2014, Max Sidnin <[email protected]> wrote:

> Hi, there is the question about synchronized on
> "org.h2.engine.Engine#openSession" method. For example we have two
> simultaneous threads. Each of them opens a connection to separate DB file.
> If one of these threads will run some heavy operation inside connection
> creation (like restoring DB files after JVM crash) another one will wait on
> "openSession". It is clear why connections to the same DB should do that,
> but why a separate one should?
>
> *Info:*
>
>    - H2 Version: checked in 182 (found in 176)
>    - Used connection URL:
>
>    
> jdbc:h2:D:/tmp/8.6/h2/DB_NAME;LOG=1;MVCC=TRUE;PAGE_SIZE=16384;CACHE_TYPE=TQ;ALIAS_COLUMN_NAME=TRUE;IGNORECASE=TRUE;MAX_MEMORY_ROWS=100000;DB_CLOSE_DELAY=0;CIPHER=AES;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3
>
>
> There is next threads dump in that moment:
>
> *Thread #1 opens connection to DB #1*
> -------------------------------------------------------------------
> "Thread #1"@599 in group "main": RUNNING
> getEntry():-1, ZipFile {java.util.zip}
> getEntry():306, ZipFile {java.util.zip}
> getEntry():227, JarFile {java.util.jar}
> getJarEntry():210, JarFile {java.util.jar}
> getResource():840, URLClassPath$JarLoader {sun.misc}
> getResource():199, URLClassPath {sun.misc}
> run():358, URLClassLoader$1 {java.net}
> run():355, URLClassLoader$1 {java.net}
> doPrivileged():-1, AccessController {java.security}
> findClass():354, URLClassLoader {java.net}
> loadClass():425, ClassLoader {java.lang}
> loadClass():308, Launcher$AppClassLoader {sun.misc}
> loadClass():358, ClassLoader {java.lang}
> getPageStore():2381, Database {org.h2.engine}
> open():666, Database {org.h2.engine}
> openDatabase():266, Database {org.h2.engine}
> <init>():260, Database {org.h2.engine}
> openSession():60, Engine {org.h2.engine}
> openSession():167, Engine {org.h2.engine}
> createSessionAndValidate():145, Engine {org.h2.engine}
> createSession():128, Engine {org.h2.engine}
> createSession():26, Engine {org.h2.engine}
> connectEmbeddedOrServer():347, SessionRemote {org.h2.engine}
> <init>():108, JdbcConnection {org.h2.jdbc}
> <init>():92, JdbcConnection {org.h2.jdbc}
> connect():72, Driver {org.h2}
> getConnection():571, DriverManager {java.sql}
> getConnection():215, DriverManager {java.sql}
> createConnection():160, H2CompactingTest {com.keysurvey.contact}
> access$000():23, H2CompactingTest {com.keysurvey.contact}
> run():46, H2CompactingTest$1 {com.keysurvey.contact}
> run():745, Thread {java.lang}
>
>
> *Thread #2 opens connection to the same DB #1*
> -------------------------------------------------------------------
> "Thread #2"@602 in group "main": MONITOR
> openSession():160, Engine {org.h2.engine}
> createSessionAndValidate():145, Engine {org.h2.engine}
> createSession():128, Engine {org.h2.engine}
> createSession():26, Engine {org.h2.engine}
> connectEmbeddedOrServer():347, SessionRemote {org.h2.engine}
> <init>():108, JdbcConnection {org.h2.jdbc}
> <init>():92, JdbcConnection {org.h2.jdbc}
> connect():72, Driver {org.h2}
> getConnection():571, DriverManager {java.sql}
> getConnection():215, DriverManager {java.sql}
> createConnection():160, H2CompactingTest {com.keysurvey.contact}
> access$000():23, H2CompactingTest {com.keysurvey.contact}
> run():76, H2CompactingTest$2 {com.keysurvey.contact}
> run():745, Thread {java.lang}
>
>
> *Thread #3 opens connection to the different DB #2*
> -------------------------------------------------------------------
> "Thread #3"@604 in group "main": MONITOR *<--- Why?*
> openSession():160, Engine {org.h2.engine}
> createSessionAndValidate():145, Engine {org.h2.engine}
> createSession():128, Engine {org.h2.engine}
> createSession():26, Engine {org.h2.engine}
> connectEmbeddedOrServer():347, SessionRemote {org.h2.engine}
> <init>():108, JdbcConnection {org.h2.jdbc}
> <init>():92, JdbcConnection {org.h2.jdbc}
> connect():72, Driver {org.h2}
> getConnection():571, DriverManager {java.sql}
> getConnection():215, DriverManager {java.sql}
> createConnection():160, H2CompactingTest {com.keysurvey.contact}
> access$000():23, H2CompactingTest {com.keysurvey.contact}
> run():106, H2CompactingTest$3 {com.keysurvey.contact}
> run():745, Thread {java.lang}
> -------------------------------------------------------------------
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <javascript:_e(%7B%7D,'cvml','h2-database%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to