Example usage for java.util.concurrent TimeUnit MINUTES

List of usage examples for java.util.concurrent TimeUnit MINUTES

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MINUTES.

Prototype

TimeUnit MINUTES

To view the source code for java.util.concurrent TimeUnit MINUTES.

Click Source Link

Document

Time unit representing sixty seconds.

Usage

From source file:gobblin.aws.GobblinAWSUtils.java

/***
 * Initiates an orderly shutdown in which previously submitted
 * tasks are executed, but no new tasks are accepted.
 * Invocation has no additional effect if already shut down.
 *
 * This also blocks until all tasks have completed execution
 * request, or the timeout occurs, or the current thread is
 * interrupted, whichever happens first.
 * @param clazz {@link Class} that invokes shutdown on the {@link ExecutorService}.
 * @param executorService {@link ExecutorService} to shutdown.
 * @param logger {@link Logger} to log shutdown for invoking class.
 * @throws InterruptedException if shutdown is interrupted.
 *///  w  w w  .  j a  v  a2 s .c  o  m
public static void shutdownExecutorService(Class clazz, ExecutorService executorService, Logger logger)
        throws InterruptedException {
    executorService.shutdown();
    if (!executorService.awaitTermination(DEFAULT_EXECUTOR_SERVICE_SHUTDOWN_TIME_IN_MINUTES,
            TimeUnit.MINUTES)) {
        logger.warn("Executor service shutdown timed out.");
        List<Runnable> pendingTasks = executorService.shutdownNow();
        logger.warn(String.format("%s was shutdown instantly. %s tasks were not executed: %s", clazz.getName(),
                pendingTasks.size(), StringUtils.join(pendingTasks, ",")));
    }
}

From source file:ch.windmobile.server.socialmodel.mogodb.HeavyLoadTest.java

public void testFullChatCycle() throws Exception {
    ServiceLocator locator = new MongoDBServiceLocator().connect(null);
    try {/*from w  w w .  j ava 2 s  .com*/
        final int CNT = 50000;
        final Executor executor = Executors.newFixedThreadPool(10);
        final ChatService chatService = locator.getService(ChatService.class);
        final AtomicInteger counter = new AtomicInteger();
        final CountDownLatch latch = new CountDownLatch(CNT);
        for (int i = 0; i < CNT; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    chatService.postMessage("TestRoom", "aUser",
                            "Hello, this is my message " + counter.incrementAndGet(), "");
                    latch.countDown();
                }
            });
        }
        System.out.println("Chat sent, waiting for the end...");
        latch.await(2, TimeUnit.MINUTES);
        Messages ret = chatService.findMessages("TEST", 5);
        System.out.println("result : " + ret);
    } finally {
        locator.disconnect();
    }
}

From source file:com.vmware.identity.performanceSupport.PerfDataSink.java

/**
 *
 * @param aHitCountInterval  Triggering reportSummary dump by total number
 *                           of measurements received periodically
 * @param aMinutesInterval   Triggering reportSummary dump by time interval
 *                           specified in minute. This will be translated
 *                           to millis internally.
 *///  w  w w. ja v a  2  s .com
public PerfDataSink(long aHitCountInterval, long aMinutesInterval) {
    Validate.isTrue(aHitCountInterval > 0);
    Validate.isTrue(aMinutesInterval > 0);

    log.info("restarting PerfDataSink.");

    hitCountInterval = aHitCountInterval;
    millisInterval = TimeUnit.MINUTES.toMillis(aMinutesInterval);

    this.timer = new Thread(new Runnable() {

        @Override
        public void run() {
            do {
                try {
                    Thread.sleep(millisInterval);
                    timeIntervalReporter.reportSummary();
                } catch (InterruptedException e) {
                    log.info("thread exiting: {}", timeIntervalReporter);
                    break;
                }
            } while (true);
        }
    });

    timer.start();
}

From source file:com.hpcloud.util.Duration.java

public static Duration mins(long count) {
    return new Duration(count, TimeUnit.MINUTES);
}

From source file:app.service.CaptchaService.java

@Autowired
public CaptchaService(UserInfoValidator userInfoValidator, LsPushProperties lsPushProperties,
        JavaMailSender mailSender, TemplateEngine templateEngine, ObjectMapper objectMapper,
        UserRepository userRepo) {/*w w  w.j a v a2s.co m*/
    mUserInfoValidator = userInfoValidator;
    serverName = lsPushProperties.getServerName();
    serverUrl = lsPushProperties.getServerUrl();
    serverEmail = lsPushProperties.getServerEmail();
    mMailSender = mailSender;
    mTemplateEngine = templateEngine;
    mObjectMapper = objectMapper;
    mUserRepo = userRepo;
    mAuthCodeMap = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(500)
            .expireAfterWrite(30, TimeUnit.MINUTES).build();

    mStringFunnel = (Funnel<String>) (from, into) -> into.putString(from, StandardCharsets.UTF_8);
    resetBloomFilter();
}

From source file:io.cloudslang.lang.cli.services.ConsolePrinterImplTest.java

@Test
public void testWaitForAllPrintTasksToFinish() throws Exception {
    when(lastTask.get(1, TimeUnit.MINUTES)).thenReturn(null);

    consolePrinter.waitForAllPrintTasksToFinish();

    verify(lastTask, times(1)).get(1, TimeUnit.MINUTES);
}

From source file:com.tinspx.util.concurrent.TimedSemaphoreTest.java

@Test
public void testInit() throws InterruptedException {
    TimedSemaphore ts = TimedSemaphore.minutes(3, 17);
    assertEquals(17, ts.getPeriod());//  ww w.  ja  v a  2  s . c om
    assertSame(TimeUnit.MINUTES, ts.getUnit());
    assertEquals(3, ts.getLimit());
    assertSame(Ticker.systemTicker(), ts.getTicker());
    assertEquals(3, ts.availablePermits());

    ts.setPeriod(15, TimeUnit.MILLISECONDS);
    ts.setLimit(2);
    assertEquals(15, ts.getPeriod());
    assertSame(TimeUnit.MILLISECONDS, ts.getUnit());
    assertEquals(2, ts.getLimit());
    assertEquals(2, ts.availablePermits());

    assertEquals(0, ts.getAcquireCount());
    assertEquals(0, ts.getPeriodCount());
    assertEquals(0, ts.getAverageAcquiresPerPeriod(), 0);
    assertEquals(0, ts.estimatedWait());
    assertTrue(ts.nanosRemaining() > 10000000); //more than 10ms

    ts.acquire(3);
    assertEquals(3, ts.getAcquireCount());
    assertEquals(1, ts.getPeriodCount());
    assertEquals(2, ts.getAverageAcquiresPerPeriod(), 0);
    assertEquals(0, ts.estimatedWait());
    assertTrue(ts.nanosRemaining() > 10000000); //more than 10ms
    assertEquals(1, ts.availablePermits());

    assertTrue(ts.tryAcquire());
    assertEquals(4, ts.getAcquireCount());
    assertEquals(1, ts.getPeriodCount());
    assertEquals(2, ts.getAverageAcquiresPerPeriod(), 0);
    assertTrue(ts.estimatedWait() > 10000000);
    assertTrue(ts.nanosRemaining() > 10000000); //more than 10ms
    assertEquals(0, ts.availablePermits());
}

From source file:com.spawnin.battlecat.core.config.NetworkConfig.java

@Bean
public Reconnect reconnect() {

    List<Long> retries = new ArrayList<Long>() {
        {//ww  w .  j  a  v a  2  s.  c  o  m
            add(TimeUnit.SECONDS.toMillis(10));
            add(TimeUnit.SECONDS.toMillis(30));
            add(TimeUnit.MINUTES.toMillis(1));
        }
    };

    return new ListRepeatReconnect(retries);
}

From source file:gov.nih.nci.caxchange.messaging.RegistrationLoadTest.java

/**
 * Testcase for sending the messages//from   w  w  w. j a  v  a  2 s. c o m
 * 
 * @throws InterruptedException - InterruptedException
 */
@Test
public void sendRegistrationMessage() throws InterruptedException {

    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currDt.getTime() + 5000);
    currDt = calendar.getTime();

    final Timer timer = new Timer();
    timer.schedule(getTimerTask(0), currDt);
    timer.schedule(getTimerTask(1), currDt);
    timer.schedule(getTimerTask(2), currDt);
    timer.schedule(getTimerTask(3), currDt);
    timer.schedule(getTimerTask(4), currDt);
    timer.schedule(getTimerTask(5), currDt);
    timer.schedule(getTimerTask(6), currDt);
    timer.schedule(getTimerTask(7), currDt);
    timer.schedule(getTimerTask(8), currDt);
    timer.schedule(getTimerTask(9), currDt);
    timer.schedule(getTimerTask(10), currDt);
    timer.schedule(getTimerTask(11), currDt);
    timer.schedule(getTimerTask(12), currDt);
    timer.schedule(getTimerTask(13), currDt);
    timer.schedule(getTimerTask(14), currDt);
    timer.schedule(getTimerTask(15), currDt);
    timer.schedule(getTimerTask(16), currDt);
    timer.schedule(getTimerTask(17), currDt);
    timer.schedule(getTimerTask(18), currDt);
    timer.schedule(getTimerTask(19), currDt);

    es.awaitTermination(3, TimeUnit.MINUTES);
}

From source file:gov.nih.nci.caxchange.messaging.AdverseEventLoadTest.java

/**
 * Testcase for sending the messages/*from w ww .j a va2 s.  c o  m*/
 * 
 * @throws InterruptedException - InterruptedException
 */
@Test
public void sendAdverseEventMessage() throws InterruptedException {

    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currDt.getTime() + 5000);
    currDt = calendar.getTime();

    final Timer timer = new Timer();
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);
    timer.schedule(getTimerTask(), currDt);

    es.awaitTermination(3, TimeUnit.MINUTES);
}