Examples of ScheduledExecutorService


Examples of java.util.concurrent.ScheduledExecutorService

    public void shouldSupportConcurrentlyCreatingNewKeys() throws InterruptedException {
        // note. this test did never actually trigger the race condition so only limited confidence here.
        // this is the best I've come up with so far for actually triggering the conditions this breaks
        int factor = 666;
        int startIndex = EfficientString.nextIndex();
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(20);
        final JsonObject o = new JsonObject();
        // this should create some potential for the race condition to trigger since it rapidly creates the same keys
        int total = 100000;
        for(int i=0;i<total;i++) {
            // make sure we are actually creating new Strings with no overlap with the other tests
            final String str="shouldSupportConcurrentlyCreatingNewKeys-"+ (i/factor);
            executorService.execute(new Runnable() {

                @Override
                public void run() {
                    o.put(str, str); // this should never fail with null key because of the (hopefully) now fixed EfficientString
                    EfficientString e = EfficientString.fromString(str);
                    assertThat(EfficientString.fromString(str), is(e));
                }
            });
        }

        executorService.shutdown();
        executorService.awaitTermination(2, TimeUnit.SECONDS);
        // check greater than so that it won't clash with concurrent executions of other tests in surefire
        assertThat(EfficientString.nextIndex()-startIndex, Matchers.greaterThan(total/factor));
    }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

        // use a temporary queue
        ReplyManager replyManager = new TemporaryQueueReplyManager(getEndpoint().getCamelContext());
        replyManager.setEndpoint(getEndpoint());

        String name = "JmsReplyManagerTimeoutChecker[" + getEndpoint().getEndpointConfiguredDestinationName() + "]";
        ScheduledExecutorService replyManagerExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(name, name);
        replyManager.setScheduledExecutorService(replyManagerExecutorService);
        ServiceHelper.startService(replyManager);

        return replyManager;
    }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

        // use a regular queue
        ReplyManager replyManager = new QueueReplyManager(getEndpoint().getCamelContext());
        replyManager.setEndpoint(getEndpoint());

        String name = "JmsReplyManagerTimeoutChecker[" + replyTo + "]";
        ScheduledExecutorService replyManagerExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(name, name);
        replyManager.setScheduledExecutorService(replyManagerExecutorService);
        ServiceHelper.startService(replyManager);

        return replyManager;
    }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

        .password("pass").connectionKey("Zombie_ROOM_1_REF_KEY_1")
        .jetserverTcpHostName("localhost").tcpPort(18090)
        .jetserverUdpHostName("255.255.255.255").udpPort(18090);
    LoginHelper loginHelper = builder.build();
    SessionFactory sessionFactory = new SessionFactory(loginHelper);
    ScheduledExecutorService taskExecutor = Executors.newSingleThreadScheduledExecutor();
    for(int i = 1; i<=50; i++){
      Session session = sessionFactory.createAndConnectSession();
      addDefaultHandlerToSession(session);
      GamePlay task = null;
      if((i % 2) == 0){
        task = new GamePlay(IAM.DEFENDER, session);
      }
      else{
        task = new GamePlay(IAM.ZOMBIE, session);
      }
      taskExecutor.scheduleAtFixedRate(task, 2000, 200, TimeUnit.MILLISECONDS);
    }
  }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

        .password("pass").connectionKey("Zombie_ROOM_1_REF_KEY_1")
        .jetserverTcpHostName("localhost").tcpPort(18090)
        .jetserverUdpHostName("255.255.255.255").udpPort(18090);
    LoginHelper loginHelper = builder.build();
    SessionFactory sessionFactory = new SessionFactory(loginHelper);
    ScheduledExecutorService taskExecutor = Executors.newSingleThreadScheduledExecutor();
    for(int i = 1; i<=50; i++){
      Session session = sessionFactory.createAndConnectSession(getDefaultHandler());
      // Set the reconnect policy for reconnection.
      session.setReconnectPolicy(new ReconnectPolicy.ReconnectNTimes(2, 2000, loginHelper));
      GamePlay task = null;
      if((i % 2) == 0){
        task = new GamePlay(IAM.DEFENDER, session);
      }
      else{
        task = new GamePlay(IAM.ZOMBIE, session);
      }
      taskExecutor.scheduleAtFixedRate(task, 2000, 200, TimeUnit.MILLISECONDS);
    }
  }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

          LOG.error("Unexpected error caught while receiving scrobbles!", t);
        }
      }
    });
   
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        try {
          scrobbleTracks();
        } catch (Throwable t) {
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

          LOG.error("Unexpected error caught while receiving scrobbles!", t);
        }
      }
    });
   
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        try {
          scrobbleTracks();
        } catch (Throwable t) {
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

    }
  }

  private void startTagUpdateService() {

    ScheduledExecutorService scheduler = Executors
        .newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        try {
          updateTags();
        } catch (Throwable t) {
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

               .setMaxSimultaneousRequestsPerHostThreshold(HostDistance.LOCAL, maxRequests);

        // Track in flight requests in a dedicated thread every second
        final AtomicBoolean excessInflightQueriesSpotted = new AtomicBoolean(false);
        final Host host = cluster.getMetadata().getHost(new InetSocketAddress(CCMBridge.IP_PREFIX + "1", 9042));
        ScheduledExecutorService openConnectionsWatcherExecutor = Executors.newScheduledThreadPool(1);
        final Runnable openConnectionsWatcher = new Runnable() {
            @Override
            public void run() {
                int inFlight = session.getState().getInFlightQueries(host);
                if (inFlight > maxRequests)
                    excessInflightQueriesSpotted.set(true);
            }
        };
        openConnectionsWatcherExecutor.scheduleAtFixedRate(openConnectionsWatcher, 200, 200, TimeUnit.MILLISECONDS);

        // Generate the load
        for (int i = 0; i < 10000; i++)
            session.executeAsync("SELECT release_version FROM system.local");

        openConnectionsWatcherExecutor.shutdownNow();
        if (excessInflightQueriesSpotted.get()) {
            fail("Inflight queries exceeded the limit");
        }
    }
View Full Code Here

Examples of java.util.concurrent.ScheduledExecutorService

        };

        // Track opened connections in a dedicated thread every one second
        final AtomicBoolean negativeOpenConnectionCountSpotted = new AtomicBoolean(false);
        final Gauge<Integer> openConnections = cluster.getMetrics().getOpenConnections();
        ScheduledExecutorService openConnectionsWatcherExecutor = Executors.newScheduledThreadPool(1);
        final Runnable openConnectionsWatcher = new Runnable() {
            @Override
            public void run() {
                Integer value = openConnections.getValue();
                if (value < 0) {
                    System.err.println("Negative value spotted for openConnection metric: " + value);
                    negativeOpenConnectionCountSpotted.set(true);
                }
            }
        };
        openConnectionsWatcherExecutor.scheduleAtFixedRate(openConnectionsWatcher, 1, 1, SECONDS);

        // Insert 100k lines in a newly created 1k columns table
        PreparedStatement insertStatement = session.prepare(generateJava349InsertStatement());
        for (int key = 0; key < numberOfInserts; key++) {
            session.executeAsync(insertStatement.bind(key)).addListener(progressReporter, progressReportExecutor);
        }

        // Wait for all inserts to happen and stop connections and progress tracking
        pendingInserts.await();
        openConnectionsWatcherExecutor.shutdownNow();
        progressReportExecutor.shutdownNow();

        if (negativeOpenConnectionCountSpotted.get()) {
            fail("Negative value spotted for open connection count");
        }
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.