File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
netcdf4/src/main/java/ucar/nc2/ffi/netcdf
uicdm/src/main/java/ucar/nc2/ui Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 66package ucar .nc2 .ffi .netcdf ;
77
88import com .google .common .base .Strings ;
9+ import com .sun .jna .Library ;
910import com .sun .jna .Native ;
11+ import java .lang .reflect .Proxy ;
1012import javax .annotation .Nullable ;
1113import ucar .nc2 .jni .netcdf .Nc4prototypes ;
1214import ucar .nc2 .jni .netcdf .Nc4wrapper ;
@@ -128,6 +130,21 @@ public static synchronized int setLogLevel(int level) {
128130 return oldlevel ;
129131 }
130132
133+ /**
134+ * Closes the netCDF-C native library.
135+ *
136+ * <p>
137+ * Call this method to ensure JNA can shut down its cleaner thread; otherwise JVM shutdown may be blocked.
138+ * </p>
139+ */
140+ public static synchronized void shutdown () {
141+ if (nc4 != null ) {
142+ Library .Handler lh = (Library .Handler ) Proxy .getInvocationHandler (nc4 );
143+ lh .getNativeLibrary ().close ();
144+ nc4 = null ;
145+ }
146+ }
147+
131148 private static Nc4prototypes load () {
132149 if (nc4 == null ) {
133150 if (jnaPath == null ) {
Original file line number Diff line number Diff line change 1616import ucar .nc2 .dods .DODSNetcdfFile ;
1717import ucar .nc2 .dt .GridDataset ;
1818import ucar .nc2 .dt .RadialDatasetSweep ;
19+ import ucar .nc2 .ffi .netcdf .NetcdfClibrary ;
1920import ucar .nc2 .ft .point .PointDatasetImpl ;
2021import ucar .nc2 .ft2 .coverage .*;
2122import ucar .nc2 .grib .GribIndexCache ;
@@ -1312,6 +1313,10 @@ public void run(Object o) {
13121313
13131314 public static void exit () {
13141315 doSavePrefsAndUI ();
1316+ // close netCDF-C library, if loaded
1317+ if (NetcdfClibrary .isLibraryPresent ()) {
1318+ NetcdfClibrary .shutdown ();
1319+ }
13151320 System .exit (0 );
13161321 }
13171322
You can’t perform that action at this time.
0 commit comments