Example usage for java.util.concurrent TimeUnit HOURS

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

Introduction

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

Prototype

TimeUnit HOURS

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

Click Source Link

Document

Time unit representing sixty minutes.

Usage

From source file:com.util.StringUtilities.java

/**
 * converts millis to [__hr __min __sec] format
 *
 * @param millis long/*from w ww  .  ja  v a2 s.c o m*/
 * @return String of duration
 */
public static String convertLongToTime(long millis) {
    String duration = String.format("%02dhr %02dmin %02dsec", TimeUnit.MILLISECONDS.toHours(millis),
            TimeUnit.MILLISECONDS.toMinutes(millis)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
    if (TimeUnit.MILLISECONDS.toHours(millis) == 0) {
        String[] split = duration.split("hr");
        duration = split[1].trim();
    }
    return duration.trim();
}

From source file:org.apache.hadoop.mapreduce.v2.app.taskclean.TaskCleanerImpl.java

public void start() {
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("TaskCleaner #%d").build();
    launcherPool = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>(), tf);
    eventHandlingThread = new Thread(new Runnable() {
        @Override//from  w w  w.j  a  va2s. c o  m
        public void run() {
            TaskCleanupEvent event = null;
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    event = eventQueue.take();
                } catch (InterruptedException e) {
                    LOG.error("Returning, interrupted : " + e);
                    return;
                }
                // the events from the queue are handled in parallel
                // using a thread pool
                launcherPool.execute(new EventProcessor(event));
            }
        }
    });
    eventHandlingThread.setName("TaskCleaner Event Handler");
    eventHandlingThread.start();
    super.start();
}

From source file:com.rcaspar.fitbitbat.FitBitBat.java

@Override
protected Scheduler scheduler() {
    log.debug("scheduler()");
    return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.HOURS);
}

From source file:com.linkedin.pinot.core.segment.index.SegmentMetadataImplTest.java

@BeforeMethod
public void setUp() throws Exception {
    INDEX_DIR = Files.createTempDirectory(SegmentMetadataImplTest.class.getName() + "_segmentDir").toFile();

    final String filePath = TestUtils
            .getFileFromResourceUrl(SegmentMetadataImplTest.class.getClassLoader().getResource(AVRO_DATA));

    // intentionally changed this to TimeUnit.Hours to make it non-default for testing
    final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.HOURS, "testTable");
    config.setSegmentNamePostfix("1");
    config.setTimeColumnName("daysSinceEpoch");
    final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
    driver.init(config);/*from   w  ww .  ja  v a  2s. c  om*/
    driver.build();
    segmentDirectory = new File(INDEX_DIR, driver.getSegmentName());
}

From source file:org.apache.metron.profiler.client.window.WindowProcessorTest.java

@Test
public void testBaseCase() {
    for (String text : new String[] { "1 hour", "1 hour(s)", "1 hours" }) {
        Window w = WindowProcessor.process(text);
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        Assert.assertEquals(1, intervals.size());
        Assert.assertEquals(now.getTime(), (long) intervals.get(0).getMaximum());
        Assert.assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), (long) intervals.get(0).getMinimum());
    }/*from  w w  w  .jav  a2s. com*/
}

From source file:org.mitre.jwt.signer.service.impl.SymmetricKeyJWTValidatorCacheService.java

public SymmetricKeyJWTValidatorCacheService() {
    validators = CacheBuilder.newBuilder().expireAfterAccess(24, TimeUnit.HOURS).maximumSize(100)
            .build(new SymmetricValidatorBuilder());
}

From source file:com.linkedin.pinot.core.segment.DefaultSegmentNameGeneratorTest.java

public SegmentGeneratorConfig CreateSegmentConfigWithoutCreator() throws Exception {
    final String filePath = TestUtils.getFileFromResourceUrl(
            DefaultSegmentNameGeneratorTest.class.getClassLoader().getResource(AVRO_DATA));
    // Intentionally changed this to TimeUnit.Hours to make it non-default for testing.
    SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.HOURS, "testTable");
    config.setSegmentNamePostfix("1");
    config.setTimeColumnName("daysSinceEpoch");
    return config;
}

From source file:org.schabi.newpipe.util.InfoCache.java

public void putInfo(@NonNull Info info) {
    if (DEBUG)/*from w w w  .j av  a2  s .  c o  m*/
        Log.d(TAG, "putInfo() called with: info = [" + info + "]");
    synchronized (lruCache) {
        final CacheData data = new CacheData(info, DEFAULT_TIMEOUT_HOURS, TimeUnit.HOURS);
        lruCache.put(keyOf(info), data);
    }
}

From source file:org.apache.carbondata.sdk.file.ConcurrentSdkWriterTest.java

@Test
public void testWriteFiles() throws IOException {
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    Field[] fields = new Field[2];
    fields[0] = new Field("name", DataTypes.STRING);
    fields[1] = new Field("age", DataTypes.INT);

    ExecutorService executorService = Executors.newFixedThreadPool(numOfThreads);
    try {/*  w  w w . jav  a2s  .co m*/
        CarbonWriterBuilder builder = CarbonWriter.builder().outputPath(path).withThreadSafe(numOfThreads);
        CarbonWriter writer = builder.withCsvInput(new Schema(fields)).writtenBy("ConcurrentSdkWriterTest")
                .build();
        // write in multi-thread
        for (int i = 0; i < numOfThreads; i++) {
            executorService.submit(new WriteLogic(writer));
        }
        executorService.shutdown();
        executorService.awaitTermination(2, TimeUnit.HOURS);
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    // read the files and verify the count
    CarbonReader reader;
    try {
        reader = CarbonReader.builder(path, "_temp1121").projection(new String[] { "name", "age" }).build();
        int i = 0;
        while (reader.hasNext()) {
            Object[] row = (Object[]) reader.readNextRow();
            i++;
        }
        Assert.assertEquals(i, numOfThreads * recordsPerItr);
        reader.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    FileUtils.deleteDirectory(new File(path));
}

From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java

@Test
public void testNegativePeriod() throws Exception {
    assertPeriodQuery("-1M", 1, TimeUnit.MINUTES);
    assertPeriodQuery("-12h", 12, TimeUnit.HOURS);
    assertPeriodQuery("-1", 1, TimeUnit.DAYS);
    assertPeriodQuery("-4711", 4711, TimeUnit.DAYS);
    assertPeriodQuery("-H", 1, TimeUnit.HOURS);
    assertPeriodQuery("-", 1, TimeUnit.DAYS);
    assertPeriodQuery("-0", 1, TimeUnit.DAYS);
}