# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Users\Franz\Documents\NetBeansProjects\JOSM-Plugins\core\src\org\openstreetmap\gui\jmapviewer
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: JobDispatcher.java
--- JobDispatcher.java Base (BASE)
+++ JobDispatcher.java Locally Modified (Based On LOCAL)
@@ -5,6 +5,7 @@
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * A generic class that processes a list of {@link Runnable} one-by-one using
@@ -45,12 +46,12 @@
     /**
      * Total number of worker threads currently idle or active
      */
-    protected int workerThreadCount = 0;
+    protected AtomicInteger workerThreadCount = new AtomicInteger();
 
     /**
      * Number of worker threads currently idle
      */
-    protected int workerThreadIdleCount = 0;
+    protected AtomicInteger workerThreadIdleCount = new AtomicInteger();
 
     /**
      * Just an id for identifying an worker thread instance
@@ -67,7 +68,7 @@
     public void addJob(Runnable job) {
         try {
             jobQueue.put(job);
-            if (workerThreadIdleCount == 0 && workerThreadCount < WORKER_THREAD_MAX_COUNT)
+            if (workerThreadIdleCount.get() == 0 && workerThreadCount.get() < WORKER_THREAD_MAX_COUNT)
                 addWorkerThread();
         } catch (InterruptedException e) {
         }
@@ -75,9 +76,7 @@
 
     protected JobThread addWorkerThread() {
         JobThread jobThread = new JobThread(++workerThreadId);
-        synchronized (this) {
-            workerThreadCount++;
-        }
+        workerThreadCount.incrementAndGet();
         jobThread.start();
         return jobThread;
     }
@@ -96,17 +95,13 @@
         @Override
         public void run() {
             executeJobs();
-            synchronized (instance) {
-                workerThreadCount--;
+            workerThreadCount.decrementAndGet();
             }
-        }
 
         protected void executeJobs() {
             while (!isInterrupted()) {
                 try {
-                    synchronized (instance) {
-                        workerThreadIdleCount++;
-                    }
+                    workerThreadIdleCount.incrementAndGet();
                     if (firstThread)
                         job = jobQueue.take();
                     else
@@ -114,20 +109,14 @@
                 } catch (InterruptedException e1) {
                     return;
                 } finally {
-                    synchronized (instance) {
-                        workerThreadIdleCount--;
+                    workerThreadIdleCount.decrementAndGet();
                     }
-                }
                 if (job == null)
                     return;
-                try {
                     job.run();
                     job = null;
-                } catch (Exception e) {
-                    e.printStackTrace();
                 }
             }
         }
-    }
 
 }
