ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/engine/OnExitDatabaseCloser.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/engine/OnExitDatabaseCloser.java
Status
scanned
Type
file
Name
OnExitDatabaseCloser.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
3616 (3.5 KB)
MD5
d76eebec8eaa89f9f95ebf98f75c069a
SHA1
2b6ae1028f4ca44818358f77708bb7e70301232b
SHA256
525e7b07e9d7304954e9b9251cdcfc4cea889635b54bcb22e4d79d37674b129c
SHA512

      
    
SHA1_git
4ca9a6d3b05d6c363515cd47500a40a293c6604f
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
OnExitDatabaseCloser.java | 3.5 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.engine; import java.util.WeakHashMap; import org.h2.message.Trace; /** * This class is responsible to close a database on JVM shutdown. */ class OnExitDatabaseCloser extends Thread { private static final WeakHashMap<Database, Void> DATABASES = new WeakHashMap<>(); private static final Thread INSTANCE = new OnExitDatabaseCloser(); private static boolean registered; private static boolean terminated; /** * Register database instance to close one on the JVM process shutdown. * * @param db Database instance. */ static synchronized void register(Database db) { if (terminated) { // Shutdown in progress return; } DATABASES.put(db, null); if (!registered) { // Mark as registered unconditionally to avoid further attempts to register a // shutdown hook in case of exception. registered = true; try { Runtime.getRuntime().addShutdownHook(INSTANCE); } catch (IllegalStateException e) { // shutdown in progress - just don't register the handler // (maybe an application wants to write something into a // database at shutdown time) } catch (SecurityException e) { // applets may not do that - ignore // Google App Engine doesn't allow // to instantiate classes that extend Thread } } } /** * Unregister database instance. * * @param db Database instance. */ static synchronized void unregister(Database db) { if (terminated) { // Shutdown in progress, do nothing // This method can be called from the onShutdown() return; } DATABASES.remove(db); if (DATABASES.isEmpty() && registered) { try { Runtime.getRuntime().removeShutdownHook(INSTANCE); } catch (IllegalStateException e) { // ignore } catch (SecurityException e) { // applets may not do that - ignore } registered = false; } } private static void onShutdown() { synchronized(OnExitDatabaseCloser.class) { terminated = true; } RuntimeException root = null; for (Database database : DATABASES.keySet()) { try { database.close(true); } catch (RuntimeException e) { // this can happen when stopping a web application, // if loading classes is no longer allowed // it would throw an IllegalStateException try { database.getTrace(Trace.DATABASE).error(e, "could not close the database"); // if this was successful, we ignore the exception // otherwise not } catch (Throwable e2) { e.addSuppressed(e2); if (root == null) { root = e; } else { root.addSuppressed(e); } } } } if (root != null) { throw root; } } private OnExitDatabaseCloser() { } @Override public void run() { onShutdown(); } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
2.81
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220