Ejemplo n.º 1
0
  /**
   * Called by the parent thread to process work requests posted for it. This method does not return
   * unless there are no further pending requests to be processed AND all child threads have
   * terminated. If there are no requests to be processed, but some child threads are still active,
   * then the parent thread will block within this method awaiting further requests (for example,
   * those that will eventually result from the termination of the currently active child threads).
   *
   * @throws IllegalStateException if the calling thread is not registered as the parent thread for
   *     this TaskManager.
   */
  public void processRequests() throws IllegalStateException {
    try {
      // Don't let any threads except Parent thread execute this method
      if (!NachosThread.currentThread().name.equals(mParentThreadName)) return;
      // Main thread waits till all requests have been served / all worker threads have been
      // finished
      while (true) {
        // Run the post doInBackground actions such as onCompletion and onCancellation
        for (Runnable response : mResponses) {
          response.run();
        }
        if (mResponses.size() == mThreadCounter) {
          break;
        } else {
          mSemaphoreForFirstThread.P();
        }
      }
    } catch (Exception ex) {

    }
  }
Ejemplo n.º 2
0
 /**
  * Initialize a new TaskManager object, and register the calling thread as the "parent" thread.
  * The parent thread is responsible (after creating at least one Task object and calling its
  * execute() method) for calling processRequests() to track the completion of "child" threads and
  * process onCompletion() or onCancellation() requests on their behalf.
  */
 public TaskManager() {
   mParentThreadName = NachosThread.currentThread().name;
 }