org.firebirdsql.gds.ng.jna.NativeResourceTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaybird Show documentation
Show all versions of jaybird Show documentation
JDBC Driver for the Firebird RDBMS
/*
* Firebird Open Source JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.gds.ng.jna;
import org.firebirdsql.gds.JaybirdSystemProperties;
import org.firebirdsql.logging.LoggerFactory;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
* Class responsible for tracking loaded native resources for cleanup/disposal on exit.
*
* @author Mark Rotteveel
* @since 4.0
*/
public final class NativeResourceTracker {
private static final List> registeredNativeResources =
Collections.synchronizedList(new ArrayList<>());
private static final List strongRegisteredNativeResources =
Collections.synchronizedList(new ArrayList<>());
private static final boolean NATIVE_RESOURCE_SHUTDOWN_DISABLED =
JaybirdSystemProperties.isNativeResourceShutdownDisabled();
// Contains either
// - null (no shutdown thread registered),
// - a Thread (shutdown thread registered),
// - or an Object (shutdown thread disabled, eg by NativeLibraryUnloadWebListener)
private static final AtomicReference