how to monitor the status of a in-memory multi-thread database?

44 views
Skip to first unread message

ye.huang

unread,
Feb 10, 2009, 9:31:28 AM2/10/09
to H2 Database
Hi, Deal all:
I am evaluating in-memory h2 for my multi-thread simulation
application. (approximate 700 threads)

I created a database using:
jdbc:h2:mem:;MULTI_THREADED=1

After the connection is obtained, i keep the connection until the
entire simulation is finished (is it ok?)

conn = DriverManager.getConnection("jdbc:h2:mem:;MULTI_THREADED=1",
"sa", "");

during the execution, i wanna check the database's status by visiting
the page "http://localhost:8082" created by command:
java -cp h2-1.1.107.jar org.h2.tools.Server

However, it seems not working. What's up? Is it possible to monitor my
in-memory h2 status externally?

By the way, is the aforementioned setting ok for my scenario, anything
missing?

Thanks in advance!
Regards
ye

Thomas Mueller

unread,
Feb 10, 2009, 2:38:51 PM2/10/09
to h2-da...@googlegroups.com
Hi,

> jdbc:h2:mem:;MULTI_THREADED=1

This will create a separate database for each connection. Is this what
you want? In that case you can only have one connection per database.
See also http://www.h2database.com/html/features.html#database_url and
http://www.h2database.com/html/features.html#memory_only_databases

If you want to share the same database, you need to give it a name as in:

jdbc:h2:mem:test1;MULTI_THREADED=1

Regards,
Thomas

ye huang

unread,
Feb 10, 2009, 4:43:45 PM2/10/09
to h2-da...@googlegroups.com
Hi, Thomas:
Sorry for pasting the wrong code, i simply erase the database's name from the real code... 
Let's say: jdbc:h2:mem:testdb;MULTI_THREADED=1

Yes, as you proposed, i just wanna to share the same database (with database name) to several threads in the application. 

The question is: whether it's possible to monitor the database "testdb" condition from an external tool? I tried to connect to "testdb" during the execution of the application, using:
"java -cp h2-1.1.107.jar org.h2.tools.Server"

It seems I am able to login "testdb" from the prompted browser page, however, the latest "testdb" content modification can't be obtained. 

Regards
ye

--

Ye Huang, Department of Informatics
University of Fribourg / Pérolles 2 - Bld de Pérolles 90
1700 Fribourg, Switzerland





Thomas Mueller

unread,
Feb 18, 2009, 2:58:23 PM2/18/09
to h2-da...@googlegroups.com
Hi,

> Let's say: jdbc:h2:mem:testdb;MULTI_THREADED=1
> Yes, as you proposed, i just wanna to share the same database (with database
> name) to several threads in the application.

This should work (it works for me).

> The question is: whether it's possible to monitor the database "testdb"
> condition from an external tool?

Yes, but then you need to start the server from within the same
process that created the database. See "Mixed Mode" in:
http://www.h2database.com/html/features.html#connection_modes

> I tried to connect to "testdb" during the
> execution of the application, using:
> "java -cp h2-1.1.107.jar org.h2.tools.Server"

This doesn't work, because you started the server from a different
process. You have two processes:

1) your application
2) the server

You need to combine them:

1) your application + the server

Therefore you can't use the Server tool. You need to start the server
from within your application, see also
http://www.h2database.com/html/tutorial.html#using_server "Starting
the Server within an Application".

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages