Examples of ExecutorService


Examples of java.util.concurrent.ExecutorService

              // If the TX is rolled back, then we don't send the request.
              if (!success) return;

              // The invocation must happen in a separate thread, holding on the afterCompletion
              // blocks other operations that could have been listed there as well.
              ExecutorService executorService = executionEnvironment.getExecutorService();
              executorService.submit(executionCallable);
            }
           
            public void beforeCompletion(){}
          }
      );

      mex.replyAsync();
    }
    else
    {
      // one-way invocation, also defer the invoke until the transaction commits.
      Scheduler scheduler = executionEnvironment.getScheduler();
      executionCallable = new OneWayCallable(mex.getMessageExchangeId());
     
      scheduler.registerSynchronizer(new Scheduler.Synchronizer() {
   
    public void beforeCompletion() {
     
    }
   
    public void afterCompletion(boolean success) {
      if (!success) return;
     
        ExecutorService executorService = executionEnvironment.getExecutorService();
        executorService.submit(executionCallable);
    }
  });
     
      mex.replyOneWayOk();
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

  @Test
  public void simpleConcurrentGetRequestTest() {
    int nThreads = 8;
    int nRequests = 2048;
    final CountDownLatch latch = new CountDownLatch(nRequests);
    ExecutorService executor = Executors.newFixedThreadPool(nThreads);

    for (int i = 1; i <= nRequests; i++) {
      executor.submit(new Runnable() {

        @Override
        public void run() {
          try {
            doSimpleGetRequest();
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        testng.run();
    }

    @Test(dataProvider = "rand_xmark_remote_10set")
    public void scenario_invoke_random20_xmark_queries(final String[] tests) {
        ExecutorService exec = Executors.newFixedThreadPool(64);
        final int len = tests.length;
        final AtomicInteger counter = new AtomicInteger(0);
        try {
            for(int i = 0; i < len; i++) {
                exec.execute(new Runnable() {
                    public void run() {
                        int nth = counter.getAndIncrement();
                        String testfilename = tests[nth];
                        String test = FileUtils.basename(testfilename) + "#" + nth;
                        //String[] args = new String[] { "-q", testfilename, "-o", OUTPUT_DEST + test };
View Full Code Here

Examples of java.util.concurrent.ExecutorService

      stopCache3(true);
   }

   public void testAvoidConcurrentStatePush() throws Exception
   {
      final ExecutorService executor = Executors.newFixedThreadPool(2);
      final CountDownLatch pushStateCanFinish = new CountDownLatch(1);
      final CountDownLatch secondActiveStatusChangerCanStart = new CountDownLatch(1);
      final MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(pushStateCanFinish, secondActiveStatusChangerCanStart, new SingletonStoreDefaultConfig());

      Future f1 = executor.submit(createActiveStatusChanger(mscl));
      secondActiveStatusChangerCanStart.await();

      Future f2 = executor.submit(createActiveStatusChanger(mscl));

      f1.get();
      f2.get();

      assertEquals(1, mscl.getNumberCreatedTasks());
View Full Code Here

Examples of java.util.concurrent.ExecutorService

  public void setPassword(String password) {
    _password = password;
  }

   public void connectToServer(final int connectTimeoutMillis, final int readTimeoutMillis) throws Exception {       
        ExecutorService executor = Executors.newSingleThreadExecutor();    
        Future<Boolean> future = executor.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
                HttpClientParams params = new HttpClientParams();
                params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, connectTimeoutMillis);
                params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, readTimeoutMillis);
                Map<String,Object> props = new HashMap<String, Object>();
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        });
        future.get((connectTimeoutMillis + readTimeoutMillis), TimeUnit.MILLISECONDS);
    }
 
  public void connectToServer() throws Exception {   
    ExecutorService executor = Executors.newSingleThreadExecutor();   
        Future<Boolean> future = executor.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
              _services = ClientFactory.createCoreServiceClient(_url.toString());
        _session = _services.adminLogin(_user, _password);
        return Boolean.TRUE;
            }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    DozerField dozerField = mock(DozerField.class);
    when(dozerField.getName()).thenReturn("");
    fieldMap.setSrcField(dozerField);
    fieldMap.setDestField(dozerField);

    ExecutorService executorService = Executors.newFixedThreadPool(10);
    List<Callable<Object>> callables = new ArrayList<Callable<Object>>();
    for (int i=0; i < 30; i++) {
      callables.add(new Callable<Object>() {
        public Object call() throws Exception {
          return fieldMap.getSrcPropertyDescriptor(String.class);
        }
      });
    }

    executorService.invokeAll(callables);
    Thread.sleep(1000);
    executorService.shutdown();
  }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

  }

  @Test
  public void shouldInitializeOnce() throws Exception {
    final CallTrackingMapper mapper = new CallTrackingMapper();
    ExecutorService executorService = Executors.newFixedThreadPool(10);

    final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);

    HashSet<Callable<Object>> callables = new HashSet<Callable<Object>>();

    for (int i = 0; i < THREAD_COUNT; i++) {
      callables.add(new Callable<Object>() {
        public Object call() throws Exception {
          latch.countDown();
          latch.await();
          Mapper processor = mapper.getMappingProcessor();
          assertNotNull(processor);
          return null;
        }
      });
    }
    executorService.invokeAll(callables);
    assertEquals(1, mapper.getCalls());
    assertTrue(exceptions.isEmpty());
  }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        this.nthreads = nthreads;
    }

    @Override
    public void run(final TestResult result) {
        final ExecutorService exec = Executors.newFixedThreadPool(nthreads);
        final Enumeration<Test> tests = tests();
        while(tests.hasMoreElements()) {
            final Test test = tests.nextElement();
            exec.execute(new Runnable() {
                public void run() {
                    try {
                        test.run(result);
                    } catch (Throwable e) {
                        e.printStackTrace();
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        InetSocketAddress sockaddr = new InetSocketAddress(addr, port);
        servSocket.bind(sockaddr);
    }

    public void run() {
        final ExecutorService execPool = this.execPool;
        final TransferRequestListener handler = this.handler;
        try {
            while(true) {
                SocketChannel channel = serverChannel.accept();
                execPool.execute(new RequestHandler(channel, handler));
            }
        } catch (ClosedByInterruptException interrupted) {
            if(LOG.isDebugEnabled()) {
                LOG.debug("Avoidable interrupt happened (Normal case): " + interrupted.getMessage());
            }
        } catch (IOException ioe) {
            LOG.error(ioe);
        } catch (Throwable th) {
            LOG.error(th);
        } finally {
            execPool.shutdown();
            try {
                serverChannel.close();
            } catch (IOException ie) {
                if(LOG.isDebugEnabled()) {
                    LOG.debug(PrintUtils.prettyPrintStackTrace(ie, -1));
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.