Package java.util.concurrent

Examples of java.util.concurrent.ExecutorService


                    Handler_playtimepromote.promotionTask.cancel();
                    Handler_playtimepromote.promotionTask = CommandsEX.plugin.getServer().getScheduler().runTaskTimerAsynchronously(CommandsEX.plugin, new Runnable() {
                    @Override
                    public void run() {
                      // create ExecutorService to manage threads                       
                      ExecutorService threadExecutor = Executors.newFixedThreadPool(1);
                      threadExecutor.execute(new Runnable() {
                        @Override
                        public void run() {
                          Handler_playtimepromote.checkTimedPromotions();
                        }
                      });
                      threadExecutor.shutdown(); // shutdown worker threads
                    }
                  }, (20 * Integer.parseInt(args[2])), (20 * Integer.parseInt(args[2])));
                } catch (Throwable ex) {}
               
                // show message
                sender.sendMessage(ChatColor.YELLOW + _("configUpdated", sender.getName()) + ChatColor.WHITE + p.getConfig().getString("timedPromoteTaskTime"));
              } else {
                // timeout not numeric
                LogHelper.showWarning("configProvideNumericValue", sender);
              }
            } else {
              LogHelper.showWarnings(sender, "configUnspecifiedError1", "configUnspecifiedError2", "configUnspecifiedError3");
            }
          } else if (v.equals("ecopromotetasktime")) {
            if ((aLength > 2) && (args[0].equals("cs") ? args[2].toLowerCase() : args[3].toLowerCase()) != null) {
              if ((args[0].equals("cs") ? args[2].toLowerCase() : args[3].toLowerCase()).matches(CommandsEX.intRegex)) {
                p.getConfig().set("ecoPromoteTaskTime", Integer.valueOf((args[0].equals("cs") ? args[2].toLowerCase() : args[3].toLowerCase())));
                p.saveConfig();

                // cancel old task and create a new one with this new timeout value
                try {
                    Handler_economypromote.promotionTask.cancel();
                    Handler_economypromote.promotionTask = CommandsEX.plugin.getServer().getScheduler().runTaskTimerAsynchronously(CommandsEX.plugin, new Runnable() {
                    @Override
                    public void run() {
                      // create ExecutorService to manage threads                       
                      ExecutorService threadExecutor = Executors.newFixedThreadPool(1);
                      threadExecutor.execute(new Runnable() {
                        @Override
                        public void run() {
                          Handler_economypromote.checkTimedPromotions();
                        }
                      });
                      threadExecutor.shutdown(); // shutdown worker threads
                    }
                  }, (20 * Integer.parseInt((args[0].equals("cs") ? args[2].toLowerCase() : args[3].toLowerCase()))), (20 * Integer.parseInt((args[0].equals("cs") ? args[2].toLowerCase() : args[3].toLowerCase()))));
                } catch (Throwable ex) {}
               
                // show message
View Full Code Here


        doReturn(english).when(provider, "createResourceBundle", eq(null), eq(Locale.ENGLISH));
        doReturn(german).when(provider, "createResourceBundle", eq(null), eq(Locale.GERMAN));

        final int numberOfThreads = 40;
        final ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads / 2);
        for (int i = 0; i < numberOfThreads; i++) {
            final Locale language = i < numberOfThreads / 2 ? Locale.ENGLISH : Locale.GERMAN;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    provider.getResourceBundle(language);
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.SECONDS);

        verifyPrivate(provider, times(1)).invoke("createResourceBundle", eq(null), eq(Locale.ENGLISH));
        verifyPrivate(provider, times(1)).invoke("createResourceBundle", eq(null), eq(Locale.GERMAN));
    }
View Full Code Here

         destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
      this.deploymentUnit = deploymentUnit;
     
      // Get the Async Invocation Processor from the Deployment
      final String asyncInvocationProcessorName = org.jboss.ejb3.async.spi.AttachmentNames.ASYNC_INVOCATION_PROCESSOR;
      final ExecutorService es = (ExecutorService) unit.getAttachment(asyncInvocationProcessorName);
      if (es == null)
      {
         throw new IllegalStateException(unit + " must contain an attachment of name " + asyncInvocationProcessorName);
      }
      this.asynchronousProcessor = es;
View Full Code Here

      if (!(transport.getThreadFactory() instanceof ThreadFactoryAdapter)) {
                transport.setThreadFactory(new ThreadFactoryAdapter(threadFactory));
            }
    }
   
    ExecutorService defaultExecutor = transportConfig.getDefaultExecutor();
    if (defaultExecutor != null) {
            if (!(transport.getDefaultThreadPool() instanceof ManagedExecutorService)) {
                transport.setDefaultThreadPool(new ManagedExecutorService(defaultExecutor));
            }
        }
   
    ExecutorService oobExecutor = transportConfig.getOOBExecutor();
        if (oobExecutor != null) {
            if (!(transport.getOOBThreadPool() instanceof ManagedExecutorService)) {
                transport.setOOBThreadPool(new ManagedExecutorService(oobExecutor));
            }
        }
View Full Code Here

    // insertion listeners
    List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>();


    //threading
    final ExecutorService executorService;
    if(nuOfThreads > 0){
      log.info("setup executor-service with " + nuOfThreads + " threads");
      executorService = Executors.newFixedThreadPool(nuOfThreads);
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() {

        @Override
        public void informAlgorithmEnds(VehicleRoutingProblem problem,Collection<VehicleRoutingProblemSolution> solutions) {
          log.info("shutdown executor-service");
          executorService.shutdown();
        }
      }));
      Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread arg0, Throwable arg1) {
          System.err.println(arg1.toString());
          System.exit(0);
        }
      });
      Runtime.getRuntime().addShutdownHook(new Thread(){
        public void run(){
          if(!executorService.isShutdown()){
            System.err.println("shutdowHook shuts down executorService");
            executorService.shutdown();
          }
        }
      });
    }
    else executorService = null;
View Full Code Here

        new TransceiverThreadFactory("Flume Avro RPC Client Call Invoker"));
    NioClientSocketChannelFactory socketChannelFactory = null;

    try {

      ExecutorService bossExecutor =
        Executors.newCachedThreadPool(new TransceiverThreadFactory(
          "Avro " + NettyTransceiver.class.getSimpleName() + " Boss"));
      ExecutorService workerExecutor =
        Executors.newCachedThreadPool(new TransceiverThreadFactory(
          "Avro " + NettyTransceiver.class.getSimpleName() + " I/O Worker"));

      if (enableDeflateCompression || enableSsl) {
        if (maxIoWorkers >= 1) {
View Full Code Here

  }
  @Test
  public void testPutGet() throws InterruptedException, IOException {
    final List<Throwable> errors =
        Collections.synchronizedList(new ArrayList<Throwable>());
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    CompletionService<Void> completionService = new ExecutorCompletionService
      <Void>(executorService);
    final LogFile.RandomReader logFileReader =
        LogFileFactory.getRandomReader(dataFile, null, true);
    for (int i = 0; i < 1000; i++) {
View Full Code Here

  @Test
  public void testGroupCommit() throws Exception {
    final FlumeEvent eventIn = TestUtils.newPersistableEvent(250);
    final CyclicBarrier barrier = new CyclicBarrier(20);
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    ExecutorCompletionService<Void> completionService = new
      ExecutorCompletionService<Void>(executorService);
    final LogFile.Writer writer = logFileWriter;
    final AtomicLong txnId = new AtomicLong(++transactionID);
    for (int i = 0; i < 20; i++) {
      completionService.submit(new Callable<Void>() {
        @Override
        public Void call() {
          try {
            Put put = new Put(txnId.incrementAndGet(),
              WriteOrderOracle.next(), eventIn);
            ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
            writer.put(bytes);
            writer.commit(TransactionEventRecord.toByteBuffer(
              new Commit(txnId.get(), WriteOrderOracle.next())));
            barrier.await();
            writer.sync();
          } catch (Exception ex) {
            Throwables.propagate(ex);
          }
          return null;
        }
      });
    }

    for(int i = 0; i < 20; i++) {
      completionService.take().get();
    }

    //At least 250*20, but can be higher due to serialization overhead
    Assert.assertTrue(logFileWriter.position() >= 5000);
    Assert.assertEquals(1, writer.getSyncCount());
    Assert.assertTrue(logFileWriter.getLastCommitPosition() ==
      logFileWriter.getLastSyncPosition());

    executorService.shutdown();

  }
View Full Code Here

                manager.start();

                if (mainClass != null)
                    injector.getInstance(mainClass);

                final ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("GovernatorStandaloneTerminator-%d").build());
                executor.execute(new Runnable() {
                        @Override
                        public void run() {
                            LOG.info("Waiting for terminate event");
                            try {
                                terminateEvent.await();
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            }
                            LOG.info("Terminating application");
                            manager.close();
                            executor.shutdown();
                        }
                    });
            }
            catch (Exception e) {
                LOG.error("Error executing application ", e);
View Full Code Here

     * Events may expire during the evaluation of accumulate.
     */
    @Test
    public void testFireUntilHaltWithAccumulateAndExpires() throws Exception {
        // thread for firing until halt
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        final Future sessionFuture = executor.submit(new Runnable() {

            public void run() {
                statefulSession.fireUntilHalt();
            }
        });
View Full Code Here

TOP

Related Classes of java.util.concurrent.ExecutorService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.