From e190a04ee4f77b515ed2b33b2b7fb324d8c38b04 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 6 Jul 2006 18:37:38 +0000 Subject: [PATCH] use boolean flag to check state in close method --- bindings/java/src/org/hyperic/sigar/Sigar.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/Sigar.java b/bindings/java/src/org/hyperic/sigar/Sigar.java index 9d324179..5ff6b664 100644 --- a/bindings/java/src/org/hyperic/sigar/Sigar.java +++ b/bindings/java/src/org/hyperic/sigar/Sigar.java @@ -51,6 +51,7 @@ public class Sigar implements SigarProxy { private static SigarLoader loader = new SigarLoader(Sigar.class); private FileSystemMap mounts = null; + private boolean open = false; int sigarWrapper = 0; //holds the sigar_t * long longSigarWrapper = 0; //same, but where sizeof(void*) > sizeof(int) @@ -125,6 +126,7 @@ public class Sigar implements SigarProxy { public Sigar() { try { open(); + this.open = true; } catch (SigarException e) { if (enableLogging) { e.printStackTrace(); @@ -151,9 +153,10 @@ public class Sigar implements SigarProxy { * If the close method is not called directly, the finalize method will * call it if the Sigar object is garbage collected. */ - public void close() { - if (this.sigarWrapper != 0) { + public synchronized void close() { + if (this.open) { nativeClose(); + this.open = false; } }