Package java.util.concurrent

Examples of java.util.concurrent.ExecutorService


    }
   
    protected  void testhelper(boolean useDispatcher) throws Throwable {
        final int count=8;

        final ExecutorService executor=Executors.newFixedThreadPool(count);
        final CountDownLatch latch=new CountDownLatch(count);
        final JChannel[] channels=new JChannel[count];
        final Task[] tasks=new Task[count];

        final long start=System.currentTimeMillis();
        for(int i=0;i < count;i++) {
            if(i == 0)
                channels[i]=createChannel(true, count);
            else
                channels[i]=createChannel(channels[0]);
           
            tasks[i]=new Task(latch, channels[i],useDispatcher);
            changeMergeInterval(channels[i]);
            changeViewBundling(channels[i]);
            replaceDiscoveryProtocol(channels[i]);
        }

        for(final Task t:tasks) {
            executor.execute(t);
        }

        int timeoutToConverge=120;
        boolean successConnecting  = false;
        try {
            // Wait for all channels to finish connecting
            successConnecting=latch.await(timeoutToConverge, TimeUnit.SECONDS);           
            if(successConnecting) {
                log.info("All connected. Converging...");
                for(Task t:tasks) {
                    Throwable ex=t.getException();
                    if(ex != null)
                        throw ex;
                }

                // Wait for all channels to have the correct number of members in their
                // current view
                boolean converged=false;
                for(int counter=0;counter < timeoutToConverge && !converged;SECONDS.sleep(1),counter++) {
                    for(final JChannel channel:channels) {
                        converged=channel.getView() != null && channel.getView().size() == count;
                        if(!converged)
                            break;
                    }
                }

                final long duration=System.currentTimeMillis() - start;
                log.info("Converged to a single group after " + duration
                                   + " ms; group is:\n");
                for(int i=0;i < channels.length;i++) {
                    log.info("#" + (i + 1)
                                       + ": "
                                       + channels[i].getAddress()
                                       + ": "
                                       + channels[i].getView());
                }               
            }        

            for(final JChannel channel:channels) {
                assertEquals("View ok for channel " + channel.getAddress(), count, channel.getView().size());
            }
            assertTrue("All channels were succefully connected",successConnecting);    
        }
        finally {
            Util.sleep(2500);
            executor.shutdownNow();
            log.info("closing channels: ");           
            for(JChannel ch:channels) {
                ch.close();                              
                //there are sometimes big delays until entire cluster shuts down
                //use sleep to make a smoother shutdown so we avoid false positives
View Full Code Here


                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionSync(pager, cache, capacity, round, percent, scanLength, reader);
                            } else {
                                runBenchmarkWithZipfDistributionLock(lock, pager, cache, capacity, round, percent, scanLength, reader);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }
View Full Code Here

                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionLongHashSync(pager, hash, capacity, round, percent, scanLength, reader);
                            } else {
                                runBenchmarkWithZipfDistributionLongHashLock(lock, pager, hash, capacity, round, percent, scanLength, reader);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }
View Full Code Here

                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength + ", pageSize: " + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                final int threadId = i;
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionSync(pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionLock(lock, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }
View Full Code Here

                + ", invocations: " + total + ", scanPercentage: " + percent + ", scanLength: "
                + scanLength + ", pageSize: " + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);

        final ExecutorService exec = Executors.newFixedThreadPool(threads);
        try {
            for(int i = 0; i < threads; i++) {
                final int threadId = i;
                exec.submit(new Runnable() {
                    public void run() {
                        try {
                            if(lock == null) {
                                runBenchmarkWithZipfDistributionLongHashSync(pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionLongHashLock(lock, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } finally {
            exec.shutdown();
            try {
                exec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                ;
            }
        }
View Full Code Here

              // 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

  @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

        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

      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

  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

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.