Repository: hazelcast/hazelcast-simulator
Issue: IllegalThreadStateException for WorkerPerformanceMonitorThread

```
Failure[
   message='Worked ran into an unhandled exception'
   type='Worker exception'
   agentAddress=10.184.183.169
   time=Tue May 19 15:52:34 UTC 2015
   workerAddress=10.184.183.169:5702
   workerId=worker-10.184.183.169-1-server
   test=null unknown
   cause=java.lang.IllegalThreadStateException
        at java.lang.Thread.start(Thread.java:705)
        at com.hazelcast.simulator.worker.WorkerPerformanceMonitor.start(WorkerPerformanceMonitor.java:36)
        at com.hazelcast.simulator.worker.WorkerCommandRequestProcessor$WorkerCommandRequestProcessorThread.process(WorkerCommandRequestProcessor.java:195)
        at com.hazelcast.simulator.worker.WorkerCommandRequestProcessor$WorkerCommandRequestProcessorThread.doProcess(WorkerCommandRequestProcessor.java:121)
        at com.hazelcast.simulator.worker.WorkerCommandRequestProcessor$WorkerCommandRequestProcessorThread.run(WorkerCommandRequestProcessor.java:106)

]
```

why for this super complex start?

```
 boolean start() {
        if (!thread.running) {
            synchronized (this) {
                if (!thread.running) {
                    thread.running = true;
                    thread.start();

                    return true;
                }
            }
        }
        return false;
    }
```


Changed files:
simulator/src/main/java/com/hazelcast/simulator/worker/WorkerPerformanceMonitor.java

diff --git a/simulator/src/main/java/com/hazelcast/simulator/worker/WorkerPerformanceMonitor.java b/simulator/src/main/java/com/hazelcast/simulator/worker/WorkerPerformanceMonitor.java
index a25a19ad6..676ab5f9e 100644
--- a/simulator/src/main/java/com/hazelcast/simulator/worker/WorkerPerformanceMonitor.java
+++ b/simulator/src/main/java/com/hazelcast/simulator/worker/WorkerPerformanceMonitor.java
@@ -10,6 +10,7 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static com.hazelcast.simulator.utils.CommonUtils.fillString;
 import static com.hazelcast.simulator.utils.CommonUtils.formatDouble;
@@ -22,33 +23,29 @@ import static java.lang.String.format;
  */
 class WorkerPerformanceMonitor {
 
-    private final WorkerPerformanceMonitorThread workerPerformanceMonitorThread;
+    private final MonitorThread thread;
+    private final AtomicBoolean started = new AtomicBoolean();
 
     WorkerPerformanceMonitor(Collection<TestContainer<TestContext>> testContainers) {
-        workerPerformanceMonitorThread = new WorkerPerformanceMonitorThread(testContainers);
+        thread = new MonitorThread(testContainers);
     }
 
     boolean start() {
-        if (!workerPerformanceMonitorThread.running) {
-            synchronized (this) {
-                if (!workerPerformanceMonitorThread.running) {
-                    workerPerformanceMonitorThread.running = true;
-                    workerPerformanceMonitorThread.start();
-
-                    return true;
-                }
-            }
+        if (!started.compareAndSet(false, true)) {
+            return false;
         }
-        return false;
+
+        thread.start();
+        return true;
     }
 
     void stop() {
-        workerPerformanceMonitorThread.running = false;
+        thread.stop = true;
     }
 
-    private static final class WorkerPerformanceMonitorThread extends Thread {
+    private static final class MonitorThread extends Thread {
 
-        private static final Logger LOGGER = Logger.getLogger(WorkerPerformanceMonitorThread.class);
+        private static final Logger LOGGER = Logger.getLogger(MonitorThread.class);
 
         private final File globalPerformanceFile = new File("performance.txt");
         private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
@@ -58,9 +55,9 @@ class WorkerPerformanceMonitor {
         private long globalLastOpsCount;
         private long globalLastTimeMillis = System.currentTimeMillis();
 
-        private volatile boolean running;
+        private volatile boolean stop;
 
-        private WorkerPerformanceMonitorThread(Collection<TestContainer<TestContext>> testContainers) {
+        private MonitorThread(Collection<TestContainer<TestContext>> testContainers) {
             super("WorkerPerformanceMonitorThread");
             setDaemon(true);
 
@@ -71,7 +68,7 @@ class WorkerPerformanceMonitor {
 
         @Override
         public void run() {
-            while (running) {
+            while (!stop) {
                 try {
                     Thread.sleep(5000);
                     writeStatsToFiles();