INTERNAL: reduce synchronized method in DataThread.java 44/38344/2
authorgreatim <jaewon81.lim@samsung.com>
Fri, 17 Apr 2015 05:56:16 +0000 (14:56 +0900)
committergreatim <jaewon81.lim@samsung.com>
Tue, 21 Apr 2015 06:25:17 +0000 (15:25 +0900)
reduce synchorized method in DataThread.java

Change-Id: I69af5edca1c128612bd57a184b14a06b90a27419
Signed-off-by: greatim <jaewon81.lim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/DataThread.java

index 7b8bbb1..6a10703 100644 (file)
@@ -33,6 +33,7 @@ import org.tizen.dynamicanalyzer.util.Logger;
 public abstract class DataThread<E> implements Runnable {
 
        private Thread thread = null;
+       private final Object threadLock = new Object();
 
        private BlockingQueue<E> dataQueue = new LinkedBlockingQueue<E>();
 
@@ -54,62 +55,68 @@ public abstract class DataThread<E> implements Runnable {
                }
        }
 
-       public synchronized final boolean start() {
-               if (isThreadAlive()) {
-                       try {
-                               thread.interrupt();
-                               thread.join();
-                               thread = null;
-                       } catch (InterruptedException e) {
-                               Logger.exception(e);
-                               return false;
+       public final boolean start() {
+               synchronized (threadLock) {
+                       if (isThreadAlive()) {
+                               try {
+                                       thread.interrupt();
+                                       thread.join();
+                                       thread = null;
+                               } catch (InterruptedException e) {
+                                       Logger.exception(e);
+                                       return false;
+                               }
                        }
-               }
 
-               clearQueue();
-               resetBeforeStart();
+                       clearQueue();
+                       resetBeforeStart();
 
-               thread = new Thread(null, this, getThreadName());
-               thread.start();
+                       thread = new Thread(null, this, getThreadName());
+                       thread.start();
 
-               return workAfterStart();
+                       return workAfterStart();
+               }
        }
 
-       public synchronized final boolean stopNormal() {
-               if (isThreadAlive()) {
-                       try {
-                               thread.join();
-                               thread = null;
-                               Logger.debug(getThreadName() + " thread joined!"); //$NON-NLS-1$
-                       } catch (InterruptedException e) {
-                               Logger.exception(e);
-                               return false;
+       public final boolean stopNormal() {
+               synchronized (threadLock) {
+                       if (isThreadAlive()) {
+                               try {
+                                       thread.join();
+                                       thread = null;
+                                       Logger.debug(getThreadName() + " thread joined!"); //$NON-NLS-1$
+                               } catch (InterruptedException e) {
+                                       Logger.exception(e);
+                                       return false;
+                               }
                        }
-               }
 
-               clearQueue();
-               clearAfterStop();
+                       clearQueue();
+                       clearAfterStop();
 
-               return workAfterStopNormal();
+                       return workAfterStopNormal();
+               }
        }
 
-       public synchronized final boolean stopForced() {
-               if (isThreadAlive()) {
-                       try {
-                               thread.interrupt();
-                               thread.join();
-                               thread = null;
-                               Logger.debug(getThreadName() + " thread joined!"); //$NON-NLS-1$
-                       } catch (InterruptedException e) {
-                               Logger.exception(e);
-                               return false;
+       public final boolean stopForced() {
+               synchronized (threadLock) {
+                       if (isThreadAlive()) {
+                               try {
+                                       thread.interrupt();
+                                       thread.join();
+                                       thread = null;
+                                       Logger.debug(getThreadName() + " thread joined!"); //$NON-NLS-1$
+                               } catch (InterruptedException e) {
+                                       Logger.exception(e);
+                                       return false;
+                               }
                        }
-               }
 
-               clearQueue();
-               clearAfterStop();
+                       clearQueue();
+                       clearAfterStop();
 
-               return workAfterStopForced();
+                       return workAfterStopForced();
+               }
        }
 
        public boolean isThreadAlive() {