コード例 #1
0
ファイル: SubmitThread.java プロジェクト: xiongshaogang/smmp
 /** 改变标志位停止线程 */
 public void stop_() {
   synchronized (this) {
     isContinue = false;
     watchDataThreadPool.shutdown();
     submitDataThreadPool.shutdown();
   }
 }
コード例 #2
0
ファイル: Neo4jJobScheduler.java プロジェクト: Analect/neo4j
  @Override
  public void shutdown() {
    RuntimeException exception = null;
    try {
      if (executor != null) {
        executor.shutdownNow();
        executor.awaitTermination(5, TimeUnit.SECONDS);
        executor = null;
      }
    } catch (RuntimeException e) {
      exception = e;
    } catch (InterruptedException e) {
      exception = new RuntimeException(e);
    }

    try {
      if (scheduledExecutor != null) {
        scheduledExecutor.shutdown();
        scheduledExecutor.awaitTermination(5, TimeUnit.SECONDS);
        scheduledExecutor = null;
      }
    } catch (RuntimeException e) {
      exception = e;
    } catch (InterruptedException e) {
      exception = new RuntimeException(e);
    }

    if (exception != null) {
      throw new RuntimeException("Unable to shut down job scheduler properly.", exception);
    }
  }
コード例 #3
0
 @Override
 public void serviceStop() {
   llapTaskUmbilicalServer.shutdownServer();
   timer.shutdown();
   if (this.communicator != null) {
     this.communicator.stop();
   }
 }
コード例 #4
0
  @Override
  public void stop() {
    pause();
    stpe.shutdown();
    super.stop();

    Sensor.setSensorStatus(Sensor.SENSOR_LOCATION, Sensor.SENSOR_OFF);
    refreshStatus();
  }
コード例 #5
0
 public void stopRetryProcessor() {
   if (timer == null) return;
   try {
     timer.shutdown();
   } catch (Exception e) {
     SpineToolsLogger.getInstance()
         .log("org.warlock.spine.connection.ConnectionManager.stopRetryProcessor", e);
   }
 }
コード例 #6
0
  public void shutdown() {
    _shutdown = true;
    try {
      _effectsScheduledThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalScheduledThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalPacketsThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _ioPacketsThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _effectsScheduledThreadPool.shutdown();
      _generalScheduledThreadPool.shutdown();
      _generalPacketsThreadPool.shutdown();
      _ioPacketsThreadPool.shutdown();
      _generalThreadPool.shutdown();
      _log.info("All ThreadPools are now stopped");

    } catch (InterruptedException e) {
      _log.log(Level.WARNING, "", e);
    }
  }
コード例 #7
0
  @Override
  public void onDestroy() {
    log.debug("Called onDestroy()");

    persistor.close();

    executorService.shutdown();

    super.onDestroy();
  }
コード例 #8
0
ファイル: ThreadPool.java プロジェクト: mehiel/elasticsearch
 public void shutdown() {
   estimatedTimeThread.running = false;
   estimatedTimeThread.interrupt();
   scheduler.shutdown();
   for (ExecutorHolder executor : executors.values()) {
     if (executor.executor instanceof ThreadPoolExecutor) {
       ((ThreadPoolExecutor) executor.executor).shutdown();
     }
   }
 }
コード例 #9
0
  public void terminateAudio() {
    mAudioTrack.flush();
    mAudioTrack.release();

    mAudioTrack = null;

    reqThreadrunning = false;

    stpe.shutdown();
    stpe = null;
  }
コード例 #10
0
ファイル: ThreadPoolManager.java プロジェクト: kenit/l1j-wk
  public void shutdown() {
    _shutdown = true;
    try {
      _effectsScheduledThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalScheduledThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalPacketsThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _ioPacketsThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _generalThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _aiThreadPool.awaitTermination(1, TimeUnit.SECONDS);
      _effectsScheduledThreadPool.shutdown();
      _generalScheduledThreadPool.shutdown();
      _generalPacketsThreadPool.shutdown();
      _ioPacketsThreadPool.shutdown();
      _generalThreadPool.shutdown();
      _aiThreadPool.shutdown();
      System.out.println("All ThreadPools are now stoped");

    } catch (InterruptedException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
コード例 #11
0
ファイル: Scheduler.java プロジェクト: jruyi/jruyi
  public void deactivate() {
    final ScheduledThreadPoolExecutor executor = m_executor;
    executor.shutdown();
    try {
      executor.awaitTermination(m_conf.terminationWaitTimeInSeconds(), TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      // Ignore
    }

    m_executor = null;
    m_conf = null;

    c_logger.info("Scheduler deactivated");
  }
コード例 #12
0
 @Override
 protected void serviceStop() throws Exception {
   if (sched != null) {
     sched.shutdown();
     boolean terminated = false;
     try {
       terminated = sched.awaitTermination(10, SECONDS);
     } catch (InterruptedException e) {
     }
     if (terminated != true) {
       sched.shutdownNow();
     }
   }
   super.serviceStop();
 }
コード例 #13
0
  public void stop() throws Exception {
    LOGGER.info("Shutting down Network !!");

    _state.set(State.SHUTTING_DOWN);
    _connPool.shutdown();
    _eventLoopGroup.shutdownGracefully();
    _routingTable.shutdown();
    _poolTimeoutExecutor.shutdown();
    _requestSenderPool.shutdown();
    _state.set(State.SHUTDOWN);
    LOGGER.info("Network shutdown!!");

    LOGGER.info("Stopping Jetty server !!");
    _server.stop();
    LOGGER.info("Stopped Jetty server !!");
  }
コード例 #14
0
  @Override
  public void onDestroy() {
    if (AppConfig.DEBUG) Log.d(TAG, "Service shutting down");
    isRunning = false;
    updateReport();

    stopForeground(true);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);

    downloadCompletionThread.interrupt();
    syncExecutor.shutdown();
    schedExecutor.shutdown();
    cancelNotificationUpdater();
    unregisterReceiver(cancelDownloadReceiver);
  }
コード例 #15
0
  void test(String[] args) throws Throwable {

    ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(0);
    Runnable task =
        new Runnable() {
          public void run() {
            taskRun = true;
          }
        };
    check(pool.getCorePoolSize() == 0);

    pool.schedule(task, 1, TimeUnit.SECONDS);

    pool.shutdown();
    check(pool.awaitTermination(20L, TimeUnit.SECONDS));
    check(pool.getCorePoolSize() == 0);
    check(taskRun);
  }
コード例 #16
0
 /**
  * Shuts down the task scheduler.
  *
  * @see ScheduledThreadPoolExecutor#shutdown()
  */
 public void shutdown() {
   mThreadPool.shutdown();
 }
コード例 #17
0
 @Override
 public void shutdown() throws Exception {
   scheduledExec.shutdown();
 }
コード例 #18
0
 @Override
 public void destroy() {
   super.destroy();
   exec.shutdown();
 }
コード例 #19
0
ファイル: DelayedTest.java プロジェクト: mucaho/jnetrobust
  @Test
  @Parameters
  @SuppressWarnings("unchecked")
  public final void testDelayed(
      int minDelay,
      int maxDelay,
      float lossChance,
      float dupChance,
      int executeInterval,
      long executeTime,
      boolean retransmit)
      throws InterruptedException {

    /*
     * Record phase
     */
    final UnreliableQueue<Packet<Long>> aToB =
        new UnreliableQueue<Packet<Long>>(
            queueListenerAtoB, minDelay, maxDelay, lossChance, dupChance);
    final UnreliableQueue<Packet<Long>> bToA =
        new UnreliableQueue<Packet<Long>>(
            queueListenerBtoA, minDelay, maxDelay, lossChance, dupChance);

    ProtocolListener<Long> listenerA =
        DEBUG
            ? new DebugProtocolListener<Long>(protocolListenerA, Logger.getConsoleLogger("A"))
            : protocolListenerA;
    final TestHost<Long> hostA =
        new TestHost<Long>(
            hostListenerA,
            new LongDataGenerator(),
            bToA,
            aToB,
            new ProtocolConfig<Long>(listenerA),
            DEBUG ? "A" : null);
    final List<Long> sentA = new ArrayList<Long>();
    final List<Long> lostSentA = new ArrayList<Long>();
    final List<Long> dupedSentA = new ArrayList<Long>();
    final List<Long> receivedA = new ArrayList<Long>();
    final List<Long> ackedA = new ArrayList<Long>();
    final List<Long> notAckedA = new ArrayList<Long>();
    final List<Long> orderedA = new ArrayList<Long>();
    final List<Long> unorderedA = new ArrayList<Long>();
    final List<Long> retransmitsA = new ArrayList<Long>();

    ProtocolListener<Long> listenerB =
        DEBUG
            ? new DebugProtocolListener<Long>(protocolListenerB, Logger.getConsoleLogger("B"))
            : protocolListenerB;
    final TestHost<Long> hostB =
        new TestHost<Long>(
            hostListenerB,
            new LongDataGenerator(),
            aToB,
            bToA,
            new ProtocolConfig<Long>(listenerB),
            DEBUG ? "B" : null);
    final List<Long> sentB = new ArrayList<Long>();
    final List<Long> lostSentB = new ArrayList<Long>();
    final List<Long> dupedSentB = new ArrayList<Long>();
    final List<Long> receivedB = new ArrayList<Long>();
    final List<Long> ackedB = new ArrayList<Long>();
    final List<Long> notAckedB = new ArrayList<Long>();
    final List<Long> orderedB = new ArrayList<Long>();
    final List<Long> unorderedB = new ArrayList<Long>();
    final List<Long> retransmitsB = new ArrayList<Long>();

    new NonStrictExpectations() {
      {
        hostListenerA.notifyReceived(withCapture(receivedA));
        hostListenerA.notifySent(withCapture(sentA));
        hostListenerA.notifyRetransmitted(withCapture(retransmitsA));

        protocolListenerA.handleAckedData(anyShort, withCapture(ackedA));
        protocolListenerA.handleUnackedData(anyShort, withCapture(notAckedA));
        protocolListenerA.handleOrderedData(anyShort, withCapture(orderedA));
        protocolListenerA.handleUnorderedData(anyShort, withCapture(unorderedA));
      }
    };

    new NonStrictExpectations() {
      {
        hostListenerB.notifyReceived(withCapture(receivedB));
        hostListenerB.notifySent(withCapture(sentB));
        hostListenerB.notifyRetransmitted(withCapture(retransmitsB));

        protocolListenerB.handleAckedData(anyShort, withCapture(ackedB));
        protocolListenerB.handleUnackedData(anyShort, withCapture(notAckedB));
        protocolListenerB.handleOrderedData(anyShort, withCapture(orderedB));
        protocolListenerB.handleUnorderedData(anyShort, withCapture(unorderedB));
      }
    };

    new NonStrictExpectations() {
      {
        queueListenerAtoB.notifyDuplicate((Packet<Long>) any);
        result =
            new Delegate<Packet<Long>>() {
              @SuppressWarnings("unused")
              void delegate(Packet<Long> dup) {
                for (Metadata<Long> metadata : dup.getMetadatas()) {
                  dupedSentA.add(metadata.getData());
                  if (DEBUG) System.out.println("[A-dupedSent]: " + metadata.getData());
                }
              }
            };
        queueListenerAtoB.notifyLoss((Packet<Long>) any);
        result =
            new Delegate<Packet<Long>>() {
              @SuppressWarnings("unused")
              void delegate(Packet<Long> loss) {
                for (Metadata<Long> metadata : loss.getMetadatas()) {
                  lostSentA.add(metadata.getData());
                  if (DEBUG) System.out.println("[A-lostSent]: " + metadata.getData());
                }
              }
            };

        queueListenerBtoA.notifyDuplicate((Packet<Long>) any);
        result =
            new Delegate<Packet<Long>>() {
              @SuppressWarnings("unused")
              void delegate(Packet<Long> dup) {
                for (Metadata<Long> metadata : dup.getMetadatas()) {
                  dupedSentB.add(metadata.getData());
                  if (DEBUG) System.out.println("[B-dupedSent]: " + metadata.getData());
                }
              }
            };
        queueListenerBtoA.notifyLoss((Packet<Long>) any);
        result =
            new Delegate<Packet<Long>>() {
              @SuppressWarnings("unused")
              void delegate(Packet<Long> loss) {
                for (Metadata<Long> metadata : loss.getMetadatas()) {
                  lostSentB.add(metadata.getData());
                  if (DEBUG) System.out.println("[B-lostSent]: " + metadata.getData());
                }
              }
            };
      }
    };

    /*
     * Replay phase
     */

    // play it for a longer interval
    executor.scheduleAtFixedRate(hostA, 0, executeInterval, TimeUnit.MILLISECONDS);
    executor.scheduleAtFixedRate(
        hostB, executeInterval / 2, executeInterval, TimeUnit.MILLISECONDS);
    executor.schedule(
        new Runnable() {
          @Override
          public void run() {
            // enable reliable queue mode for final messages
            aToB.setDupChance(0f);
            aToB.setLossChance(0f);
            aToB.setMinDelay(0L);
            aToB.setMaxDelay(0L);
            bToA.setDupChance(0f);
            bToA.setLossChance(0f);
            bToA.setMinDelay(0L);
            bToA.setMaxDelay(0L);
          }
        },
        executeTime - executeTime / 10,
        TimeUnit.SECONDS);
    executor.awaitTermination(executeTime, TimeUnit.SECONDS);
    executor.shutdown();
    executor.awaitTermination(executeInterval * 2 + maxDelay * 2, TimeUnit.MILLISECONDS);

    // let pending messages finish
    Thread.sleep(maxDelay * 2);
    hostA.receive();
    hostB.receive();
    hostA.send();
    hostB.send();
    Thread.sleep(maxDelay * 2); // wait for queue to make all elements available
    hostA.receive();
    hostB.receive();

    System.out.println();

    /*
     * Verify phase
     */

    for (Long item : notAckedA)
      assertTrue("notAcked data should not have been acked", !ackedA.contains(item));
    for (Long item : notAckedB)
      assertTrue("notAcked data should not have been acked", !ackedB.contains(item));

    for (Long item : retransmitsA)
      assertTrue("retransmitted data should have been sent from sender", sentA.contains(item));
    for (Long item : retransmitsB)
      assertTrue("retransmitted data should have been sent from sender", sentB.contains(item));
    for (Long item : lostSentA)
      assertTrue("over medium lost data should have been sent from sender", sentA.contains(item));
    for (Long item : lostSentB)
      assertTrue("over medium lost data should have been sent from sender", sentB.contains(item));
    for (Long item : dupedSentA)
      assertTrue(
          "over medium duplicated data should have been sent from sender", sentA.contains(item));
    for (Long item : dupedSentB)
      assertTrue(
          "over medium duplicated data should have been sent from sender", sentB.contains(item));

    Long lastItem = null;
    for (Long item : orderedA) {
      assertTrue("orderly received data should have been sent from sender", sentB.contains(item));

      if (lastItem != null) {
        assertTrue("ordered data should be ordered", item > lastItem);
      }
      lastItem = item;
    }
    lastItem = null;
    for (Long item : orderedB) {
      assertTrue("orderly received data should have been sent from sender", sentA.contains(item));

      if (lastItem != null) {
        assertTrue("ordered data should be ordered", item > lastItem);
      }
      lastItem = item;
    }

    lastItem = null;
    for (Long item : unorderedA) {
      assertTrue("unorderly received data should have been sent from sender", sentB.contains(item));

      if (lastItem != null) {
        assertTrue("unordered data should be ordered", item > lastItem);
      }
      lastItem = item;

      assertTrue("unordered data should not have been orderly received", !orderedA.contains(item));

      // The following assertions can not be guaranteed, since there may be multiple unordered
      // events and multiple holes until an ordered event occurs
      //			Long pred = item;
      //			do {
      //				pred--;
      //			} while(unorderedA.contains(pred));
      //			Long succ = item;
      //			do {
      //				succ++;
      //			} while(unorderedA.contains(succ));
      //			assertTrue("ordered data contains predecessor of unorderedData",
      // orderedA.contains(pred));
      //			assertTrue("ordered data contains successor of unorderedData", orderedA.contains(succ));
    }

    lastItem = null;
    for (Long item : unorderedB) {
      assertTrue("orderly received data should have been sent from sender", sentA.contains(item));

      if (lastItem != null) {
        assertTrue("unordered data should be ordered", item > lastItem);
      }
      lastItem = item;

      assertTrue("unordered data should not have been orderly received", !orderedB.contains(item));

      // The following assertions can not be guaranteed, since there may be multiple unordered
      // events and multiple holes until an ordered event occurs
      //			Long pred = item;
      //			do {
      //				pred--;
      //			} while(unorderedB.contains(pred));
      //			Long succ = item;
      //			do {
      //				succ++;
      //			} while(unorderedB.contains(succ));
      //			assertTrue("ordered data contains predecessor of unorderedData",
      // orderedB.contains(pred));
      //			assertTrue("ordered data contains successor of unorderedData", orderedB.contains(succ));
    }

    // the following addition of "magic constants" is due to the scheduling procedure of the very
    // last messages
    assertEquals(
        "all messages from A must be received at B",
        receivedB.size(),
        sentA.size() - lostSentA.size() + dupedSentA.size());
    assertEquals(
        "all messages from A must be acked",
        ackedA.size(),
        sentA.size() - retransmitsA.size() - notAckedA.size() - 1);
    assertEquals(
        "all messages from A must be ordered at B",
        orderedB.size(),
        sentA.size() - retransmitsA.size() - unorderedB.size());

    // the following addition of "magic constants" is due to the scheduling procedure of the very
    // last messages
    assertEquals(
        "all messages from B must be received at A",
        receivedA.size(),
        sentB.size() - lostSentB.size() + dupedSentB.size());
    assertEquals(
        "all messages from B must be acked",
        ackedB.size(),
        sentB.size() - retransmitsB.size() - notAckedB.size() - 1);
    assertEquals(
        "all messages from B must be ordered at A",
        orderedA.size(),
        sentB.size() - retransmitsB.size() - unorderedA.size());

    if (lossChance == 0f) {
      assertEquals("no lost packets", 0, lostSentB.size());
      assertEquals("no lost packets", 0, lostSentA.size());
    }

    if (dupChance == 0f) {
      assertEquals("no duped packets", 0, dupedSentB.size());
      assertEquals("no duped packets", 0, dupedSentA.size());
    }

    if (retransmit || lossChance == 0f) {
      new Verifications() {
        {
          protocolListenerA.handleUnackedData(anyShort, anyLong);
          times = 0;
          protocolListenerA.handleUnorderedData(anyShort, anyLong);
          times = 0;
        }
      };
      new Verifications() {
        {
          protocolListenerB.handleUnackedData(anyShort, anyLong);
          times = 0;
          protocolListenerB.handleUnorderedData(anyShort, anyLong);
          times = 0;
        }
      };

      assertEquals("all packets acked", 0, notAckedA.size());
      assertEquals("all packets ordered", 0, unorderedA.size());
      assertEquals("all packets acked", 0, notAckedB.size());
      assertEquals("all packets ordered", 0, unorderedB.size());
    }
  }
コード例 #20
0
 private void waitForShutdown(ScheduledThreadPoolExecutor timerService)
     throws InterruptedException {
   timerService.shutdown();
   timerService.awaitTermination(20, TimeUnit.SECONDS);
 }
コード例 #21
0
 public static List<File> instrument(
     List<File> srcPaths, String instrumenterFileName, String instrumenterClassName) {
   if (instrumenterFileName == null) return srcPaths;
   if (instrumenterClassName == null) return srcPaths;
   Instrumenter instrumenter;
   try {
     List<URL> tmpUrls = new ArrayList<URL>();
     for (File file : srcPaths) {
       tmpUrls.add(file.toURI().toURL());
     }
     ClassLoader tmpLoader =
         new URLClassLoader(
             tmpUrls.toArray(new URL[tmpUrls.size()]), InstrumenterWorker.class.getClassLoader());
     instrumenter = (Instrumenter) tmpLoader.loadClass(instrumenterClassName).newInstance();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     return srcPaths;
   } catch (InstantiationException e) {
     e.printStackTrace();
     return srcPaths;
   } catch (IOException e) {
     e.printStackTrace();
     return srcPaths;
   } catch (ClassNotFoundException e) {
     return srcPaths;
   }
   ScheduledThreadPoolExecutor executor =
       new ScheduledThreadPoolExecutor(
           ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors());
   try {
     File instrumenterFile = new File(instrumenterFileName);
     instrumenterFile.delete();
     instrumenter.open(instrumenterFile, true);
     List<Future<File>> futures = new ArrayList<Future<File>>();
     for (File file : srcPaths) {
       String path = file.getPath();
       if (path.matches(".*/ofbiz[^/]*\\.(jar|zip)")) {
         futures.add(executor.submit(new FileInstrumenter(instrumenter, file)));
       } else {
         futures.add(new ConstantFutureFile(file));
       }
     }
     List<File> result = new ArrayList<File>(futures.size());
     for (Future<File> future : futures) {
       result.add(future.get());
     }
     instrumenter.close();
     return result;
   } catch (ExecutionException e) {
     e.printStackTrace();
     return srcPaths;
   } catch (InterruptedException e) {
     e.printStackTrace();
     return srcPaths;
   } catch (IOException e) {
     e.printStackTrace();
     return srcPaths;
   } finally {
     executor.shutdown();
   }
 }
コード例 #22
0
ファイル: ChildOnBus.java プロジェクト: maffan/MinBusskompis
 /** Shut down the pool executor and unbind updatetoparse serivce on detroy. */
 @Override
 protected void onDestroy() {
   super.onDestroy();
   poolExecutor.shutdown();
   unbindService(this);
 }