예제 #1
0
    public void addTask(ImageView iv, ProgressBar pb) {
      if (iv == null) return;
      iv.setVisibility(View.INVISIBLE);
      // check cache
      String url = (String) iv.getTag();
      if (url == null) return;
      Bitmap b;
      synchronized (cache) {
        b = cache.get(url);
      }
      if (b != null) {
        iv.setImageBitmap(b);
        iv.setVisibility(View.VISIBLE);
        if (pb != null) pb.setVisibility(View.GONE);
        return;
      }

      if (pb != null) pb.setVisibility(View.VISIBLE);

      // must load the image...
      if (!running) start();
      synchronized (tasks) {
        tasks.addLast(new ImageAndLoader(iv, pb));
        tasks.notify(); // notify any waiting threads
      }
    }
 public void addFinishedTarget(Target target) {
   // 向finishedTargets队列中加入一个任务
   synchronized (finishedTargets) {
     finishedTargets.notify();
     finishedTargets.add(target);
   }
 }
  /**
   * @see
   *     org.apache.james.jspf.executor.DNSAsynchLookupService#getRecordsAsynch(org.apache.james.jspf.core.DNSRequest,
   *     int, org.apache.james.jspf.executor.IResponseQueue)
   */
  public void getRecordsAsynch(DNSRequest request, int id, final IResponseQueue responsePool) {

    synchronized (queue) {
      queue.addLast(new Request(request, new Integer(id), responsePool));
      queue.notify();
    }
  }
예제 #4
0
 void scheduleJob(InternalJobImpl job) {
   System.err.println("scheduling job=" + job);
   synchronized (myJobs) {
     myJobs.add(job);
     myJobs.notify();
   }
 }
예제 #5
0
  public void startAutomatedRotation() {
    synchronized (taskQueue) {

      // Stop the previous tasks
      clearTasks();

      taskQueue.addLast(new AutomatedRotation());
      taskQueue.notify();
    }
  }
예제 #6
0
  /**
   * @param xRotation
   * @param yRotation
   * @param zRotation
   * @param time
   * @param fps
   */
  public void addRotationTask(
      double xRotation, double yRotation, double zRotation, long time, double fps) {
    synchronized (taskQueue) {

      // Stop the previus tasks
      clearTasks();

      taskQueue.addLast(new RotationTask(xRotation, yRotation, zRotation, time, fps));
      taskQueue.notify();
    }
  }
예제 #7
0
  public RotationTask startKineticMove(double fps, double retardation) {

    synchronized (taskQueue) {

      // Stop the previus tasks
      clearTasks();
      rotationTask = new RotationTask(0, 0, 0, fps, retardation);
      taskQueue.addLast(rotationTask);
      taskQueue.notify();
    }
    return rotationTask;
  }
예제 #8
0
  public RotationTask restartKineticMove() {

    synchronized (taskQueue) {

      // Stop the previus tasks
      while (taskQueue.size() > 0) {
        taskQueue.remove();
      }

      taskQueue.addLast(rotationTask);
      taskQueue.notify();
    }
    return rotationTask;
  }
예제 #9
0
  public void run() {

    while (!kill) {
      synchronized (taskQueue) {
        while (taskQueue.isEmpty()) {
          try {
            taskQueue.wait();
          } catch (InterruptedException e) {
          }
        }
        task = taskQueue.poll();
        taskQueue.notify();
      }

      task.doTask();

      task = null;
    }
  }
  public void addAction(Runnable action) {
    //
    // Make sure we don't store too many elements in the update list.
    // Block while update list is larger than the allowed maximum
    // non-blocking size.
    //
    if (actionList.size() > nonBlockingSize) {
      //			this.setPriority(Thread.NORM_PRIORITY + 2);

      while (actionList.size() > nonBlockingSize * freeFactor) {
        try {
          Thread.sleep(50);
        } catch (InterruptedException ex) {
          break;
        }
      }
    }
    synchronized (actionList) {
      actionList.addLast(action);
      actionList.notify();
    }
  }
예제 #11
0
  public void stopTask(Runnable batch) {
    synchronized (queue) {
      // 1) Look if the task isn't waiting in the queue
      if (queue.contains(batch)) {
        queue.remove(batch);
        return;
      }

      // 2) Maybe it's running
      for (int i = 0; i < threads.length; i++) {
        PoolWorker t = threads[i];

        if (batch.equals(t.getActiveTask())) {
          try {
            t.interrupt();
            queue.notify();
          } catch (Exception e) {
            e.printStackTrace();
          }
          return;
        }
      }
    }
  }
예제 #12
0
 public void execute(Runnable r) {
   synchronized (queue) {
     queue.addLast(r);
     queue.notify();
   }
 }
예제 #13
0
파일: Ping.java 프로젝트: WzYmL/doraemon
 void add(Target t) {
   synchronized (pending) {
     pending.add(t);
     pending.notify();
   }
 }
 public void stopRunning() {
   running = false;
   synchronized (actionList) {
     actionList.notify();
   }
 }
 /**
  * Put an action in front of the queue so that it's executed next or close to next. This method
  * will not block even if the size of the accumulated actions exceeds the blocking threshold
  */
 public void prependAction(Runnable action) {
   synchronized (actionList) {
     actionList.addFirst(action);
     actionList.notify();
   }
 }
예제 #16
0
 public void addTask(Runnable task) {
   synchronized (tasks) {
     tasks.addLast(task);
     tasks.notify();
   }
 }
예제 #17
0
 public void enqueueCommand(@SuppressWarnings("rawtypes") Command cmd) {
   synchronized (cmdQueue) {
     cmdQueue.addLast(cmd);
     cmdQueue.notify();
   }
 }
예제 #18
0
 public void enqueueCommands(@SuppressWarnings("rawtypes") List<Command> commands) {
   synchronized (cmdQueue) {
     cmdQueue.addAll(commands);
     cmdQueue.notify();
   }
 }
예제 #19
0
 /**
  * @param point
  * @param time
  * @param fps
  */
 public void addTranslationTask(double[] point, long time, double fps) {
   synchronized (taskQueue) {
     taskQueue.addLast(new TranslationTask(point, time, fps));
     taskQueue.notify();
   }
 }
예제 #20
0
 public void deliver(CoapExchange request, CoapResource resource) {
   synchronized (queue) {
     queue.addLast(new RequestDelivery(request, resource));
     queue.notify(); // notifyAll not required
   }
 }
예제 #21
0
 public void deliver(Runnable runnable) {
   synchronized (queue) {
     queue.addLast(runnable);
     queue.notify(); // notifyAll not required
   }
 }