From 48c96918d8da363c87e9efec446b68f01b931f57 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 21 Sep 2005 23:00:36 +0000 Subject: [PATCH] synchronize on logs --- .../hyperic/sigar/win32/EventLogThread.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java b/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java index 9abd26aa..51af8f54 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java +++ b/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java @@ -27,28 +27,33 @@ public class EventLogThread implements Runnable { private String logName = "Application"; private long interval = 10 * 1000; // Default to 10 seconds - public static synchronized EventLogThread getInstance(String name) { - EventLogThread instance = - (EventLogThread)logs.get(name); + public static EventLogThread getInstance(String name) { + EventLogThread instance; - if (instance == null) { - instance = new EventLogThread(); - instance.setLogName(name); - logs.put(name, instance); + synchronized (logs) { + instance = (EventLogThread)logs.get(name); + + if (instance == null) { + instance = new EventLogThread(); + instance.setLogName(name); + logs.put(name, instance); + } } return instance; } - public static synchronized void closeInstances() { - for (Iterator it = logs.values().iterator(); - it.hasNext();) - { - EventLogThread eventLogThread = - (EventLogThread)it.next(); - eventLogThread.doStop(); + public static void closeInstances() { + synchronized (logs) { + for (Iterator it = logs.values().iterator(); + it.hasNext();) + { + EventLogThread eventLogThread = + (EventLogThread)it.next(); + eventLogThread.doStop(); + } + logs.clear(); } - logs.clear(); } public void setInterval(long interval) {