Examples of ExecutorService


Examples of java.util.concurrent.ExecutorService

     * @param timeout
     * @return
     * @throws ExecutionException
     */
    public E call(final long timeout) throws ExecutionException {
        final ExecutorService service = Executors.newSingleThreadExecutor();
        try {
            final Future<E> taskFuture = service.submit(this.call);
            final Runnable t = new Runnable() {
                public void run() { taskFuture.cancel(true); }
            };
            service.execute(t);
            service.shutdown();
            try {
                return taskFuture.get(timeout, TimeUnit.MILLISECONDS);
            } catch (final CancellationException e) {
                // callable was interrupted
                throw new ExecutionException(e);
View Full Code Here

Examples of java.util.concurrent.ExecutorService

      Connection connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      pool.release(connection);
      connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      ExecutorService service = Executors.newSingleThreadExecutor();
      service.invokeAny(Collections.singleton(new Callable<Connection>() {
        @Override
        public Connection call() throws Exception {
          return pool.acquire(host);
        }
      }), 2, TimeUnit.SECONDS);
View Full Code Here

Examples of java.util.concurrent.ExecutorService

      Connection connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      pool.release(connection);
      connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      ExecutorService service = Executors.newSingleThreadExecutor();
      service.invokeAny(Collections.singleton(new Callable<Connection>() {
        @Override
        public Connection call() throws Exception {
          return pool.acquire(host);
        }
      }), 2, TimeUnit.SECONDS);
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    static MBeanServerConnection server;   

    public static void main(String[] args) throws Exception
    {
 
    final ExecutorService executor = Executors.newCachedThreadPool();

    // Configure the client.
    ClientBootstrap bootstrap = new ClientBootstrap(
            new NioClientSocketChannelFactory(
                executor,
                executor));

    bootstrap.setOption(
            "remoteAddress", new InetSocketAddress("localhost", 8080));

    bootstrap.setOption("reuseAddress", true);

   
    final HessianProxyFactory factory = new HessianProxyFactory(executor, "localhost:8080");
    bootstrap.setPipelineFactory(
            new RPCClientSessionPipelineFactory(new RPCClientMixinPipelineFactory(executor, factory), bootstrap));
   

    factory.setDisconnectedListener(new Runnable()
    {
      public void run()
      {
      //stop = true;
      }
    });

factory.setNewSessionListener(new Runnable()
{
  public void run()
  {
    stop = false;
    executor.execute(new Runnable()
    {
      public void run()
      {
          System.out.println("started work thread");
          Map options = new HashMap();
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    static HubServiceServer hubServiceServer;


  public static void main(String[] args) throws Exception
  {
      ExecutorService executor = Executors.newCachedThreadPool();
     
      loadData();
     
      new Timer("hosts updater", true).schedule(new TimerTask()
      {
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    static DiscoveryClient discovery = new DiscoveryClient();


  public static void main(String[] args) throws Exception
  {
      ExecutorService executor = Executors.newCachedThreadPool();
      ServicesForm form = new ServicesForm();
     
      servicesTable = new ServicesTable(form._SERVICES_TABLE);
      hosts = new HostsTable(form._HOSTS_TABLE);
      hidden = new HiddenTable(form._HIDDEN_TABLE);
View Full Code Here

Examples of java.util.concurrent.ExecutorService

      if (log.isInfoEnabled())
        log.infof("Local socket is up at :%d with %d action ready", port, actions.size());

      // 循环监听的主程序
      final SocketLock lock = new SocketLock();
      ExecutorService execs = Executors.newCachedThreadPool();
      SocketMain main = null;
      Mirror mirror = Mirror.me(klass);
      Borning<SocketMain> borning = null;
      List<SocketAtom> atoms = new LinkedList<SocketAtom>();
      while (!lock.isStop()) {
        if (log.isDebugEnabled())
          log.debug("create new main thread to wait...");
        if(borning == null)
          borning = mirror.getBorning(atoms, lock, server, service, saTable);
        main = borning.born(new Object[]{atoms, lock, server, service, saTable});

        if (log.isDebugEnabled())
          log.debug("Ready for listen");

        execs.execute(main);

        if (log.isDebugEnabled())
          log.debug("wait for accept ...");

        // 如果没有接受套接字,那么自旋判断是不是有一个连接提示要关闭整个监听
        while (!main.isAccepted()) {
          // System.out.print(".");
          // if(++i%80==0)
          // System.out.println();
          if (log.isDebugEnabled())
            log.debug("wait lock ...");

          synchronized (lock) {
            try {
              lock.wait();
            }
            catch (InterruptedException e) {
              throw Lang.wrapThrow(e);
            }
          }

          if (log.isDebugEnabled())
            log.debugf"check main accept [%s], lock [%s]",
                  main.isAccepted(),
                  lock.isStop());

          if (lock.isStop())
            break;
        }

        if (log.isDebugEnabled())
          log.debug("Created a socket");

      }

      // 关闭所有的监听,退出程序
      if (null != main && !main.isAccepted()) {
        if (log.isInfoEnabled())
          log.info("Notify waiting threads...");

        try {
          Socket ss = new Socket("127.0.0.1", port);
          OutputStream sOut = ss.getOutputStream();
          sOut.write("V~~".getBytes());
          sOut.flush();
          sOut.close();
          ss.close();
        }
        catch (Exception e) {}
      }

      if (log.isInfoEnabled())
        log.info("Stop connected threads...");

      while (!execs.isTerminated())
        execs.shutdown();

      if (log.isInfoEnabled())
        log.info("Close all sockets..");

      try {
View Full Code Here

Examples of java.util.concurrent.ExecutorService

  }
  @Test
  public void testPutGet() throws InterruptedException, IOException {
    final List<Throwable> errors =
        Collections.synchronizedList(new ArrayList<Throwable>());
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    final LogFile.RandomReader logFileReader =
        LogFileFactory.getRandomReader(dataFile, null);
    for (int i = 0; i < 1000; i++) {
      // first try and throw failures
      synchronized (errors) {
        for(Throwable throwable : errors) {
          Throwables.propagateIfInstanceOf(throwable, AssertionError.class);
        }
        // then throw errors
        for(Throwable throwable : errors) {
          Throwables.propagate(throwable);
        }
      }
      final FlumeEvent eventIn = TestUtils.newPersistableEvent();
      final Put put = new Put(++transactionID, WriteOrderOracle.next(),
          eventIn);
      ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
      FlumeEventPointer ptr = logFileWriter.put(bytes);
      final int offset = ptr.getOffset();
      executorService.submit(new Runnable() {
        @Override
        public void run() {
          try {
            FlumeEvent eventOut = logFileReader.get(offset);
            Assert.assertEquals(eventIn.getHeaders(), eventOut.getHeaders());
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        tserver = new TNonblockingServer(serverArgs);
      } else if (implType == ImplType.HS_HA) {
        THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
        CallQueue callQueue =
            new CallQueue(new LinkedBlockingQueue<Call>(), metrics);
        ExecutorService executorService = createExecutor(
            callQueue, serverArgs.getWorkerThreads());
        serverArgs.executorService(executorService)
                  .processor(processor)
                  .transportFactory(transportFactory)
                  .protocolFactory(protocolFactory);
        tserver = new THsHaServer(serverArgs);
      } else { // THREADED_SELECTOR
        TThreadedSelectorServer.Args serverArgs =
            new HThreadedSelectorServerArgs(serverTransport, conf);
        CallQueue callQueue =
            new CallQueue(new LinkedBlockingQueue<Call>(), metrics);
        ExecutorService executorService = createExecutor(
            callQueue, serverArgs.getWorkerThreads());
        serverArgs.executorService(executorService)
                  .processor(processor)
                  .transportFactory(transportFactory)
                  .protocolFactory(protocolFactory);
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        }
      }
    }

    // shut down all our thread pools
    ExecutorService toShutdown[] = { callTimeoutPool, timedRollerPool };
    for (ExecutorService execService : toShutdown) {
      execService.shutdown();
      try {
        while (execService.isTerminated() == false) {
          execService.awaitTermination(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.