@Override
 public void startThread() {
   try {
     if (syncThread == null) {
       createThread();
     }
     switch (syncThread.getState()) {
       case NEW:
         syncThread.start();
         break;
       case BLOCKED:
       case WAITING:
       case RUNNABLE:
       case TIMED_WAITING:
         Log.d(TAG, "Stopping the thread");
         stopThread();
         break;
       case TERMINATED:
         syncThread = createThread(syncThread);
         syncThread.start();
         break;
       default:
         stopThread();
         startThread();
         break;
     }
   } catch (IllegalThreadStateException e) {
     Log.e(TAG, "Exceptin starting the worker thread.");
   }
 }
 @Override
 public void stopThread() {
   try {
     if (syncThread != null && syncThread.isAlive()) {
       Log.w(TAG, "stopping the thread");
       syncThread.stopWorker(true);
       syncThread.join();
     }
   } catch (InterruptedException e) {
     Log.e(TAG, "Interrupted exception.message" + e.getMessage());
   }
 }
 @Override
 public void createThread() {
   syncThread = new SyncWorkerPublisher();
   syncThread.setPriority(3);
 }
 private SyncWorkerPublisher createThread(SyncWorkerPublisher oldInstance) {
   SyncWorkerPublisher newSyncThread = new SyncWorkerPublisher(oldInstance);
   newSyncThread.setPriority(3);
   return newSyncThread;
 }
 protected void addSyncTask(SyncTask task) {
   if (syncThread != null) {
     syncThread.addSyncTask(task);
   }
 }