only create one instance

This commit is contained in:
Doug MacEachern 2005-02-28 00:31:41 +00:00
parent 69158c8553
commit d8f0ca3bdf
1 changed files with 16 additions and 10 deletions

View File

@ -13,6 +13,8 @@ public class OperatingSystem {
private static final String ETC = private static final String ETC =
System.getProperty("sigar.etc.dir", "/etc") + "/"; System.getProperty("sigar.etc.dir", "/etc") + "/";
private static OperatingSystem instance = null;
private String name; private String name;
private String version; private String version;
private String arch; private String arch;
@ -23,19 +25,23 @@ public class OperatingSystem {
private OperatingSystem() { private OperatingSystem() {
} }
public static OperatingSystem getInstance() { public static synchronized OperatingSystem getInstance() {
OperatingSystem os = new OperatingSystem(); if (instance == null) {
Properties props = System.getProperties(); OperatingSystem os = new OperatingSystem();
os.name = props.getProperty("os.name"); Properties props = System.getProperties();
os.version = props.getProperty("os.version"); os.name = props.getProperty("os.name");
os.arch = props.getProperty("os.arch"); os.version = props.getProperty("os.version");
os.patchLevel = props.getProperty("sun.os.patch.level"); os.arch = props.getProperty("os.arch");
os.patchLevel = props.getProperty("sun.os.patch.level");
if (os.name.equals("Linux")) { if (os.name.equals("Linux")) {
os.getLinuxInfo(); os.getLinuxInfo();
}
instance = os;
} }
return os; return instance;
} }
public String getName() { public String getName() {