Exemple #1
0
 public void run() {
   try {
     for (int x = 0; ; x++) {
       data.put(new Integer(x));
       System.out.println("Insertando " + x);
     }
   } catch (InterruptedException e) {
   }
 }
Exemple #2
0
 @Override
 public void execute(Runnable command) {
   final int size = tasks.size();
   if (size == WARNING_THRESHOLD) {
     log.warn(
         "User thread has {} pending tasks, memory exhaustion may occur.\n"
             + "If you see this message, check your memory consumption and see if it's problematic or excessively spikey.\n"
             + "If it is, check for deadlocked or slow event handlers. If it isn't, try adjusting the constant \n"
             + "Threading.UserThread.WARNING_THRESHOLD upwards until it's a suitable level for your app, or Integer.MAX_VALUE to disable.",
         size);
   }
   Uninterruptibles.putUninterruptibly(tasks, command);
 }
Exemple #3
0
  public void dispatch() {
    while (true) {
      Runnable methodRequest;
      try {
        methodRequest = activationQueue.take();

        // 防止个别任务执行失败导致线程终止的代码在run方法中
        methodRequest.run();
      } catch (InterruptedException e) {
        // 处理该异常
      }
    }
  }
Exemple #4
0
  public <T> Future<T> enqueue(Callable<T> methodRequest) {
    final FutureTask<T> task =
        new FutureTask<T>(methodRequest) {

          @Override
          public void run() {
            try {
              super.run();
              // 捕获所以可能抛出的对象,避免该任务运行失败而导致其所在的线程终止。
            } catch (Throwable t) {
              this.setException(t);
            }
          }
        };

    try {
      activationQueue.put(task);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
    return task;
  }
Exemple #5
0
  public synchronized String nanny(UbaCoordinate ubaCoordinate)
      throws InterruptedException, ExecutionException {

    long now = System.currentTimeMillis();
    if (restartAtTimestamp.get() > 0 && restartAtTimestamp.get() < now) {
      status.set("Restarting");
      deployLog.log("Nanny", "restart triggered by timestamp. " + this, null);
      if (kill()) {
        lastRestart.set(now);
        restartAtTimestamp.set(-1);
      }
    }

    try {
      if (destroyed.get()) {
        status.set("Destroying");
        deployLog.log("Nanny", "tried to check a service that has been destroyed. " + this, null);
        return deployLog.getState();
      }
      if (linkedBlockingQueue.size() == 0) {
        try {
          if (redeploy.get()) {
            status.set("Redeploy");
            NannyDestroyCallable destroyTask =
                new NannyDestroyCallable(
                    instanceDescriptor.get(),
                    instancePath,
                    deployLog,
                    healthLog,
                    invokeScript,
                    ubaLog);

            deployLog.log("Nanny", "destroying in preperation to redeploy. " + this, null);
            Future<Boolean> destroyFuture = threadPoolExecutor.submit(destroyTask);
            status.set("Destroying");
            if (destroyFuture.get()) {

              NannyDeployCallable deployTask =
                  new NannyDeployCallable(
                      repositoryProvider,
                      ubaCoordinate,
                      instanceDescriptor.get(),
                      instancePath,
                      deployLog,
                      healthLog,
                      deployableValidator,
                      invokeScript,
                      ubaLog);
              deployLog.log("Nanny", "redeploying. " + this, null);
              Future<Boolean> deployedFuture = threadPoolExecutor.submit(deployTask);
              try {
                status.set("Deploying");
                if (deployedFuture.get()) {
                  try {
                    try (FileWriter writer = new FileWriter(instancePath.deployLog())) {
                      for (String line : deployLog.peek()) {
                        writer.write(line);
                      }
                    }
                    redeploy.set(false);
                    status.set("Redeployed");
                    deployLog.log("Nanny", "successfully redeployed. " + this, null);
                  } catch (Exception x) {
                    status.set("Failed redeployed");
                    deployLog.log("Nanny", "failed to redeployed. " + this, x);
                  }
                }
              } catch (ExecutionException ee) {
                status.set("Unexpected state");
                deployLog.log("Nanny", "encountered an unexpected condition. " + this, ee);
              }
            }
          }

          NannyStatusCallable nannyTask =
              new NannyStatusCallable(
                  this,
                  status,
                  startupTimestamp,
                  instanceDescriptor.get(),
                  instancePath,
                  deployLog,
                  healthLog,
                  invokeScript,
                  ubaLog,
                  haveRunConfigExtractionCache);
          if (nannyTask.callable()) {
            threadPoolExecutor.submit(nannyTask);
          } else {
            deployLog.log("Nanny", "skipped status check. " + this, null);
          }

        } catch (InterruptedException | ExecutionException x) {
          deployLog.log("Nanny", "is already running. " + this, x);
        }
        return deployLog.getState();
      } else {
        return deployLog.getState();
      }
    } finally {
      deployLog.commit();
    }
  }
Exemple #6
0
 public void stop() {
   heartscheduler.shutdown();
   queue.add("~stop~");
 }
Exemple #7
0
 public void addMag(BaseProtocol pro) {
   queue.add(pro);
 }