use boolean flag to check state in close method
This commit is contained in:
parent
170bc35076
commit
e190a04ee4
|
@ -51,6 +51,7 @@ public class Sigar implements SigarProxy {
|
||||||
private static SigarLoader loader = new SigarLoader(Sigar.class);
|
private static SigarLoader loader = new SigarLoader(Sigar.class);
|
||||||
private FileSystemMap mounts = null;
|
private FileSystemMap mounts = null;
|
||||||
|
|
||||||
|
private boolean open = false;
|
||||||
int sigarWrapper = 0; //holds the sigar_t *
|
int sigarWrapper = 0; //holds the sigar_t *
|
||||||
long longSigarWrapper = 0; //same, but where sizeof(void*) > sizeof(int)
|
long longSigarWrapper = 0; //same, but where sizeof(void*) > sizeof(int)
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ public class Sigar implements SigarProxy {
|
||||||
public Sigar() {
|
public Sigar() {
|
||||||
try {
|
try {
|
||||||
open();
|
open();
|
||||||
|
this.open = true;
|
||||||
} catch (SigarException e) {
|
} catch (SigarException e) {
|
||||||
if (enableLogging) {
|
if (enableLogging) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -151,9 +153,10 @@ public class Sigar implements SigarProxy {
|
||||||
* If the close method is not called directly, the finalize method will
|
* If the close method is not called directly, the finalize method will
|
||||||
* call it if the Sigar object is garbage collected.
|
* call it if the Sigar object is garbage collected.
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public synchronized void close() {
|
||||||
if (this.sigarWrapper != 0) {
|
if (this.open) {
|
||||||
nativeClose();
|
nativeClose();
|
||||||
|
this.open = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue