title: What is the proper way to close H2?
body: <p>This is related to this <a href="https://stackoverflow.com/questions/9971876/tomcat-doesnt-stop-how-can-i-debug-this">post</a>.<br>
  I think I am having problem with <code>H2</code> meaning that it does not close properly.<br>
  I suspect this since I see <code>myDB.lock.db</code> when I shutdown tomcat and the process does not stop.<br>
  I use Tomcat's connection pooling and the url to the database is:<br>
  <code>url="jdbc:h2:file:/opt/myOrg/tomcat/webapps/MyApplication/db/myDatabase;SCHEMA=myschema"</code>  </p>
  
  <p>From the doc <a href="http://www.h2database.com/html/features.html#closing_a_database" rel="noreferrer">close H2</a>:  </p>
  
  <blockquote>
    <p>Usually, a database is closed when the last connection to it is
    closed.... By default, a database is closed when the last connection
    is closed. However, if it is never closed, the database is closed when
    the virtual machine exits normally, using a shutdown hook</p>
  </blockquote>
  
  <p>I can not understand if I am doing something wrong.<br>
  Should I be forcing the database to close via a command?  Is this the meaning of shutdown hook?<br>
  What am I doing wrong here?  </p>
  
  <p><strong>Note:</strong><br>
  I can not find in Google an example of how to close <code>H2</code> properly (besides the statement that it closes automatically on last connection shutdown). Should I call <code>SHUTDOWN</code> myself? Is this the proper approach?<br>
  I already see votes to close the question but there has not been a reason or link on an example of what I am investigating</p>
  
  <p><strong>UPDATE:</strong><br>
  After Joonas Pulakka answer some extra info:  </p>
  
  <p>From the <code>javacore</code> I got using a <code>kill -3</code> I see the threads:   </p>
  
  <blockquote>
    <p>"H2 Log Writer MYAPPLICATION" J9VMThread:0x08DC6F00,
    j9thread_t:0x08C9B790, java/lang/Thread:0xE7206CC8, state:CW, prio=5 
    3XMTHREADINFO1            (native thread ID:0xA32, native
    priority:0x5, native policy:UNKNOWN)   3XMTHREADINFO2<br>
    (native stack address range from:0xE5E26000, to:0xE5E67000,
    size:0x41000)   3XMTHREADINFO3           Java callstack:<br>
    4XESTACKTRACE                at java/lang/Object.wait(Native Method)<br>
    4XESTACKTRACE                at
    java/lang/Object.wait(Object.java:196(Compiled Code))   4XESTACKTRACE 
    at org/h2/store/WriterThread.run(WriterThread.java:102)<br>
    4XESTACKTRACE                at java/lang/Thread.run(Thread.java:736) </p>
    
    <p>3XMTHREADINFO      "pool-8-thread-1" J9VMThread:0x087C0200,
    j9thread_t:0x0840566C, java/lang/Thread:0xE79BFC80, state:P, prio=5<br>
    3XMTHREADINFO1            (native thread ID:0xE1A, native
    priority:0x5, native policy:UNKNOWN)   3XMTHREADINFO2<br>
    (native stack address range from:0xE5F69000, to:0xE5FAA000,
    size:0x41000)   3XMTHREADINFO3           Java callstack:<br>
    4XESTACKTRACE                at sun/misc/Unsafe.park(Native Method)<br>
    4XESTACKTRACE                at
    java/util/concurrent/locks/LockSupport.park(LockSupport.java:184(Compiled
    Code))   4XESTACKTRACE                at
    java/util/concurrent/locks/AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1998(Compiled
    Code))   4XESTACKTRACE                at
    java/util/concurrent/LinkedBlockingQueue.take(LinkedBlockingQueue.java:413(Compiled
    Code))   4XESTACKTRACE                at
    java/util/concurrent/ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:958(Compiled
    Code))   4XESTACKTRACE                at
    java/util/concurrent/ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    4XESTACKTRACE                at java/lang/Thread.run(Thread.java:736) </p>
    
    <p>3XMTHREADINFO      "H2 File Lock Watchdog
    opt/myOrg/tomcat/webapps/MyApplication/db/myDatabase.lock.db"
    J9VMThread:0x08DC6900, j9thread_t:0x08C9BA24, ja<br>
    va/lang/Thread:0xE71E9018, state:CW, prio=9     3XMTHREADINFO1<br>
    (native thread ID:0xA30, native priority:0x9, native policy:UNKNOWN)<br>
    3XMTHREADINFO2            (native stack address range from:0xE5DBA000,
    to:0xE5DFB000, size:0x41000)     3XMTHREADINFO3           Java
    callstack:     4XESTACKTRACE                at
    java/lang/Thread.sleep(Native Method)    4XESTACKTRACE<br>
    at java/lang/Thread.sleep(Thread.java:851(Compiled Code))<br>
    4XESTACKTRACE                at
    org/h2/store/FileLock.run(FileLock.java:490)   4XESTACKTRACE<br>
    at java/lang/Thread.run(Thread.java:736)  </p>
    
    <p>3XMTHREADINFO      "FileWatchdog" J9VMThread:0x087C0800,
    j9thread_t:0x08C9B4FC, java/lang/Thread:0xE715D878, state:CW, prio=5<br>
    3XMTHREADINFO1            (native thread ID:0xA2C, native
    priority:0x5, native policy:UNKNOWN)   3XMTHREADINFO2<br>
    (native stack address range from:0xE5E67000, to:0xE5EA8000,
    size:0x41000)   3XMTHREADINFO3           Java callstack:<br>
    4XESTACKTRACE                at java/lang/Thread.sleep(Native Method) 
    4XESTACKTRACE                at
    java/lang/Thread.sleep(Thread.java:851(Compiled Code))   4XESTACKTRACE
    at org/apache/log4j/helpers/FileWatchdog.run(FileWatchdog.java:104)</p>
  </blockquote>