Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 DB in Memory Clean the RAM

I am using H2 DB in in-memory mode to process some data. My java application needs to keep the JVM on while dropping and re-creating or truncating or dropping all objects in H2 DB in each run. Therefore I need to use the option 'DB_CLOSE_DELAY=-1' in the DB URL.

To clean the memory after an iteration I tried using 'DROP ALL OBJECTS', 'DROP ALL OBJECTS DELETE FILES' and Truncated each table one by one. All of these achieved what I wanted by didn't delete the memory that was currently occupied by it. My database size varies from about 300MB to 2GB. Therefore after a single iteration my RAM is about 1GB occupied and did not find any solution as to what the cause of this or the resolution.

Somewhat similar to this Clear the in memory database after every testcase. But without the dbUnit and need to clear the RAM too.

Is it possible to do this without stopping the JVM.

Thanks.

like image 647
Akalanka Avatar asked Feb 11 '13 12:02

Akalanka


People also ask

What is H2 in-memory database?

H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It stores data in memory, not persist the data on disk.

How does H2 connect to memory DB?

To access an in-memory database from another process or from another computer, you need to start a TCP server in the same process as the in-memory database was created. The other processes then need to access the database over TCP/IP or TLS, using a database URL such as: jdbc:h2:tcp://localhost/mem:db1 .

What is H2 database used for?

H2 is a relational database management system written in Java. It can be embedded in Java applications or run in client-server mode. The software is available as open source software Mozilla Public License 2.0 or the original Eclipse Public License.


1 Answers

You could execute the statement shutdown. This will close the connection and the database.

like image 86
Thomas Mueller Avatar answered Sep 18 '22 06:09

Thomas Mueller