From dcfe048ad461dd07bf663586ca510e3a945b98ff Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Tue, 26 Aug 2014 12:57:27 +0200 Subject: [PATCH] Synchronized monitored list of processes --- .../main/java/org/sonar/process/Monitor.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java b/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java index 18b4f11d927..f1891535b37 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java @@ -67,7 +67,7 @@ public class Monitor extends Thread implements Terminable { @Override public void run() { for (ProcessWrapper process : processes) { - LOGGER.debug("Pinging process[{}]",process.getName()); + LOGGER.debug("Pinging process[{}]", process.getName()); try { ProcessMXBean mBean = process.getProcessMXBean(); if (mBean != null) { @@ -85,25 +85,31 @@ public class Monitor extends Thread implements Terminable { * Registers and monitors process. Note that process is probably not ready yet. */ public void registerProcess(ProcessWrapper process) throws InterruptedException { - processes.add(process); + LOGGER.info("Registering process[{}] for monitoring.", process.getName()); + synchronized (processes) { + processes.add(process); + } // starts a monitoring thread process.start(); } /** * Check continuously that registered processes are still up. If any process is down or does not answer to pings - * during the max allowed period, then thread exits. + * during the max allowed period, then thread exits. */ @Override public void run() { try { boolean ok = true; while (isRunning && ok) { - for (ProcessWrapper process : processes) { - if (!ProcessUtils.isAlive(process.process())) { - LOGGER.info("{} is down, stopping all other processes", process.getName()); - ok = false; - interrupt(); + synchronized (processes) { + LOGGER.debug("Monitoring {} processes.", processes.size()); + for (ProcessWrapper process : processes) { + if (!ProcessUtils.isAlive(process.process())) { + LOGGER.info("{} is down, stopping all other processes", process.getName()); + ok = false; + interrupt(); + } } } if (ok) { -- 2.39.5