From d8f0ca3bdf783b00ea7360eed51bd49f5e8a7f8b Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 28 Feb 2005 00:31:41 +0000 Subject: [PATCH] only create one instance --- .../net/hyperic/sigar/OperatingSystem.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/OperatingSystem.java b/bindings/java/src/net/hyperic/sigar/OperatingSystem.java index 85e8fcdc..813b7161 100644 --- a/bindings/java/src/net/hyperic/sigar/OperatingSystem.java +++ b/bindings/java/src/net/hyperic/sigar/OperatingSystem.java @@ -13,6 +13,8 @@ public class OperatingSystem { private static final String ETC = System.getProperty("sigar.etc.dir", "/etc") + "/"; + private static OperatingSystem instance = null; + private String name; private String version; private String arch; @@ -23,19 +25,23 @@ public class OperatingSystem { private OperatingSystem() { } - public static OperatingSystem getInstance() { - OperatingSystem os = new OperatingSystem(); - Properties props = System.getProperties(); - os.name = props.getProperty("os.name"); - os.version = props.getProperty("os.version"); - os.arch = props.getProperty("os.arch"); - os.patchLevel = props.getProperty("sun.os.patch.level"); + public static synchronized OperatingSystem getInstance() { + if (instance == null) { + OperatingSystem os = new OperatingSystem(); + Properties props = System.getProperties(); + os.name = props.getProperty("os.name"); + os.version = props.getProperty("os.version"); + os.arch = props.getProperty("os.arch"); + os.patchLevel = props.getProperty("sun.os.patch.level"); - if (os.name.equals("Linux")) { - os.getLinuxInfo(); + if (os.name.equals("Linux")) { + os.getLinuxInfo(); + } + + instance = os; } - return os; + return instance; } public String getName() {