当前位置: 首页>>代码示例>>Java>>正文


Java Clock.systemUTC方法代码示例

本文整理汇总了Java中java.time.Clock.systemUTC方法的典型用法代码示例。如果您正苦于以下问题:Java Clock.systemUTC方法的具体用法?Java Clock.systemUTC怎么用?Java Clock.systemUTC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.Clock的用法示例。


在下文中一共展示了Clock.systemUTC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_equals

import java.time.Clock; //导入方法依赖的package包/类
public void test_equals() {
    Clock a = Clock.systemUTC();
    Clock b = Clock.systemUTC();
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), true);
    assertEquals(b.equals(a), true);
    assertEquals(b.equals(b), true);

    Clock c = Clock.system(PARIS);
    Clock d = Clock.system(PARIS);
    assertEquals(c.equals(c), true);
    assertEquals(c.equals(d), true);
    assertEquals(d.equals(c), true);
    assertEquals(d.equals(d), true);

    assertEquals(a.equals(c), false);
    assertEquals(c.equals(a), false);

    assertEquals(a.equals(null), false);
    assertEquals(a.equals("other type"), false);
    assertEquals(a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)), false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKClock_System.java

示例2: testCase03

import java.time.Clock; //导入方法依赖的package包/类
private static void testCase03() {
    RedPacketsContext context = new RedPacketsContext();
    Random rand = new Random();
    final Clock clockStart = Clock.systemUTC();
    long start = clockStart.millis();

    for (int i = 0; i < 1000000; i++) {
        int totalMoney = rand.nextInt(200) + 1;
        int totalPeople = rand.nextInt(100) + 1;
        checkResult(totalMoney, totalPeople, context);
    }

    final Clock clockEnd = Clock.systemUTC();
    long end = clockEnd.millis();

    System.out.println((end-start)/1000 + " Seconds passed");

}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:19,代码来源:TestCase.java

示例3: testClock

import java.time.Clock; //导入方法依赖的package包/类
public static void testClock() throws InterruptedException {
    //时钟提供给我们用于访问某个特定 时区的 瞬时时间、日期 和 时间的。  
    Clock c1 = Clock.systemUTC(); //系统默认UTC时钟(当前瞬时时间 System.currentTimeMillis())  
    System.out.println(c1.millis()); //每次调用将返回当前瞬时时间(UTC)  
    Clock c2 = Clock.systemDefaultZone(); //系统默认时区时钟(当前瞬时时间)  
    Clock c31 = Clock.system(ZoneId.of("Europe/Paris")); //巴黎时区  
    System.out.println(c31.millis()); //每次调用将返回当前瞬时时间(UTC)  
    Clock c32 = Clock.system(ZoneId.of("Asia/Shanghai"));//上海时区  
    System.out.println(c32.millis());//每次调用将返回当前瞬时时间(UTC)  
    Clock c4 = Clock.fixed(Instant.now(), ZoneId.of("Asia/Shanghai"));//固定上海时区时钟  
    System.out.println(c4.millis());
    Thread.sleep(1000);
    System.out.println(c4.millis()); //不变 即时钟时钟在那一个点不动  
    Clock c5 = Clock.offset(c1, Duration.ofSeconds(2)); //相对于系统默认时钟两秒的时钟  
    System.out.println(c1.millis());
    System.out.println(c5.millis());
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:18,代码来源:TimeIntroduction.java

示例4: ExpirationBasedCache

import java.time.Clock; //导入方法依赖的package包/类
ExpirationBasedCache()
{
    _cache = new ConcurrentHashMap<>();
    _clock = Clock.systemUTC();

    Timer timer = new Timer("cacheExpiration", true);
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            expireCacheEntries();
        }} , 60, 60);
}
 
开发者ID:curityio,项目名称:oauth-filter-for-java,代码行数:13,代码来源:ExpirationBasedCache.java

示例5: initialize

import java.time.Clock; //导入方法依赖的package包/类
synchronized void initialize(String servers) {
    if (isInitialized.get()) {
        logger.warn("Already initialized");
        return;
    }

    try {
        Properties props = new Properties();
        props.put("bootstrap.servers", servers);
        props.put("group.id", groupId);
        props.put("key.deserializer", StringDeserializer.class.getName());
        props.put("value.deserializer", StringDeserializer.class.getName());
        props.put("heartbeat.interval.ms", "10000");
        props.put("session.timeout.ms", "20000");
        props.put("enable.auto.commit", Boolean.toString(enableAutoCommit));
        props.put("auto.offset.reset", offsetReset.toString().toLowerCase());
        realConsumer = new KafkaConsumer<>(props);

        List<String> topics = new ArrayList<String>();
        topics.add(topic);
        realConsumer.subscribe(topics, this);

        offsetCommitter = new OffsetCommitter(realConsumer, Clock.systemUTC());
        primaryExecutor = Executors.newSingleThreadExecutor();
        primaryExecutor.submit(this);
        isInitialized.set(true);
    } catch (Exception ex) {
        logger.error("Error building Kafka consumer", ex);
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:31,代码来源:KafkaSubscriber.java

示例6: givenReadingFromEmptyStorePosition_readsFromTheCache

import java.time.Clock; //导入方法依赖的package包/类
@Test
public void
givenReadingFromEmptyStorePosition_readsFromTheCache() throws Exception {
    underlyingEventStore.write(stream_1, singletonList(event_1));
    saveAllToCache(getCacheFile("cache.gz"));

    assertThat(readAllFromEmpty(cacheEventReader), hasSize(1));

    CacheEventReader newCacheEventReader = new CacheEventReader(new JavaInMemoryEventStore(Clock.systemUTC()), CODEC, cacheDirectory, "cache");
    assertThat(readAllFromEmpty(newCacheEventReader), hasSize(1));
    assertThat(readAllFromEmpty(newCacheEventReader), equalTo(readAllToList(underlyingEventStore)));
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:13,代码来源:CachingEventsTest.java

示例7: testInstant

import java.time.Clock; //导入方法依赖的package包/类
public static void testInstant() {
    //瞬时时间 相当于以前的System.currentTimeMillis()  
    Instant instant1 = Instant.now();
    System.out.println(instant1.getEpochSecond());//精确到秒 得到相对于1970-01-01 00:00:00 UTC的一个时间  
    System.out.println(instant1.toEpochMilli()); //精确到毫秒  
    Clock clock1 = Clock.systemUTC(); //获取系统UTC默认时钟  
    Instant instant2 = Instant.now(clock1);//得到时钟的瞬时时间  
    System.out.println(instant2.toEpochMilli());
    Clock clock2 = Clock.fixed(instant1, ZoneId.systemDefault()); //固定瞬时时间时钟  
    Instant instant3 = Instant.now(clock2);//得到时钟的瞬时时间  
    System.out.println(instant3.toEpochMilli());//equals instant1  
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:13,代码来源:TimeIntroduction.java

示例8: testConstructor

import java.time.Clock; //导入方法依赖的package包/类
/**
 * Tests the constructor sets things appropriately.
 */
@Test
public void testConstructor() {
    // Define inputs
    final MessageBus messageBus = new MessageBus(new FifoBuffer());
    final Map<VirtualSpoutIdentifier, Queue<MessageId>> ackQueue = Maps.newConcurrentMap();
    final Map<VirtualSpoutIdentifier, Queue<MessageId>> failQueue = Maps.newConcurrentMap();
    final Clock clock = Clock.systemUTC();

    // Define some config params
    final long consumerStateFlushInterval = 200L;

    // Create our spout delegate
    final DelegateSpout spout = mock(DelegateSpout.class);

    // Create config
    final Map<String, Object> topologyConfig = getDefaultConfig(consumerStateFlushInterval);

    // Create instance.
    SpoutRunner spoutRunner = new SpoutRunner(
        spout,
        messageBus,
        clock,
        topologyConfig
    );

    // Call getters and validate!
    assertEquals("Clock instance is what we expect", clock, spoutRunner.getClock());
    assertEquals("TopologyConfig looks legit", topologyConfig, spoutRunner.getTopologyConfig());
    assertEquals(
        "getConsumerStateFlushIntervalMs() returns right value",
        consumerStateFlushInterval,
        spoutRunner.getConsumerStateFlushIntervalMs()
    );

    assertNotNull("StartTime is null", spoutRunner.getStartTime());
    assertNotEquals("StartTime is not zero", 0, spoutRunner.getStartTime());
    assertEquals("Spout delegate got set", spout, spoutRunner.getSpout());
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:42,代码来源:SpoutRunnerTest.java

示例9: test_instant

import java.time.Clock; //导入方法依赖的package包/类
public void test_instant() {
    Clock system = Clock.systemUTC();
    assertEquals(system.getZone(), ZoneOffset.UTC);
    for (int i = 0; i < 10000; i++) {
        // assume can eventually get these within 10 milliseconds
        Instant instant = system.instant();
        long systemMillis = System.currentTimeMillis();
        if (systemMillis - instant.toEpochMilli() < 10) {
            return;  // success
        }
    }
    fail();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKClock_System.java

示例10: newJob

import java.time.Clock; //导入方法依赖的package包/类
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {

    JobDetail jobDetail = bundle.getJobDetail();
    MetricRegistry metricRegistry = autowireCapableBeanFactory.getBean(MetricRegistry.class);
    HistorianDAO historianDAO = autowireCapableBeanFactory.getBean(HistorianDAO.class);
    AfterDAO afterDAO = autowireCapableBeanFactory.getBean(AfterDAO.class);

    try {
        return new TriggerAwareLoggingJob(
                new HistorianJob(
                        new TimedJob(
                                new ErrorHandlingJob(
                                        (Job) autowireCapableBeanFactory.autowire(jobDetail.getJobClass(),
                                                AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false)
                                ),
                                metricRegistry
                        ),
                        Clock.systemUTC(),
                        scheduler.getSchedulerName(),
                        scheduler.getSchedulerInstanceId(),
                        historianDAO,
                        afterDAO
                )
        );
    } catch (Exception e) {
        throw new SchedulerException(
                "Problem instantiating class '"
                        + jobDetail.getJobClass().getName() + "'", e);
    }
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:32,代码来源:DelegatingQuartzJobFactory.java

示例11: test_millis

import java.time.Clock; //导入方法依赖的package包/类
public void test_millis() {
    Clock system = Clock.systemUTC();
    assertEquals(system.getZone(), ZoneOffset.UTC);
    for (int i = 0; i < 10000; i++) {
        // assume can eventually get these within 10 milliseconds
        long instant = system.millis();
        long systemMillis = System.currentTimeMillis();
        if (systemMillis - instant < 10) {
            return;  // success
        }
    }
    fail();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TCKClock_System.java

示例12: TokenlessClientLogger

import java.time.Clock; //导入方法依赖的package包/类
public TokenlessClientLogger(Service<HttpRequest, HttpResponse> delegate) {
    this(delegate, Clock.systemUTC());
}
 
开发者ID:line,项目名称:centraldogma,代码行数:4,代码来源:TokenlessClientLogger.java

示例13: test_withZone_fromUTC

import java.time.Clock; //导入方法依赖的package包/类
public void test_withZone_fromUTC() {
    Clock test = Clock.systemUTC();
    Clock changed = test.withZone(PARIS);
    assertEquals(changed.getZone(), PARIS);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKClock_System.java

示例14: TradingHoursServiceImpl

import java.time.Clock; //导入方法依赖的package包/类
public TradingHoursServiceImpl() {
    this.clock = Clock.systemUTC();
}
 
开发者ID:mumukiller,项目名称:stock-patterns-recognition,代码行数:4,代码来源:TradingHoursServiceImpl.java

示例15: testOpenandCloseOnSpoutIsCalled

import java.time.Clock; //导入方法依赖的package包/类
/**
 * Tests that
 *   - our latch counts down when we start the thread.
 *   - open() is called on the spout on startup.
 *   - close() is called on the spout on shutdown.
 *   - spoutRunner.requestStop() shuts down the instance.
 *   - spoutDelegate.requestStop() shuts down the instance.
 */
@Test
@UseDataProvider("provideTrueAndFalse")
public void testOpenandCloseOnSpoutIsCalled(final boolean shutdownViaSpout) throws InterruptedException {
    // Define inputs
    final Clock clock = Clock.systemUTC();
    final DefaultVirtualSpoutIdentifier virtualSpoutId = new DefaultVirtualSpoutIdentifier("MyVirtualSpoutId");

    // Define some config params
    final long consumerStateFlushInterval = TimeUnit.MILLISECONDS.convert(maxWaitTime, TimeUnit.SECONDS);

    // Create our spout delegate
    final MockDelegateSpout mockSpout = new MockDelegateSpout(virtualSpoutId);

    // Setup mock MessageBus
    final VirtualSpoutMessageBus messageBus = mock(VirtualSpoutMessageBus.class);
    when(messageBus.getAckedMessage(eq(virtualSpoutId))).thenReturn(null);
    when(messageBus.getFailedMessage(eq(virtualSpoutId))).thenReturn(null);

    // Create config
    final Map<String, Object> topologyConfig = getDefaultConfig(consumerStateFlushInterval);

    // Create instance.
    SpoutRunner spoutRunner = new SpoutRunner(
        mockSpout,
        messageBus,
        clock,
        topologyConfig
    );

    // Start in a separate thread.
    final CompletableFuture future = startSpoutRunner(spoutRunner);

    // Wait for open to be called since it runs async.
    await()
        .atMost(maxWaitTime, TimeUnit.SECONDS)
        .until(() -> mockSpout.wasOpenCalled, equalTo(true));

    // Verify open was called once, but not close
    assertTrue("Open was called on our mock spout", mockSpout.wasOpenCalled);
    assertFalse("Close has not been called yet on our mock spout", mockSpout.wasCloseCalled);

    // Verify queues got setup
    verify(messageBus, times(1)).registerVirtualSpout(eq(virtualSpoutId));

    // But not torn down yet
    verify(messageBus, never()).unregisterVirtualSpout(anyObject());

    // Shut down
    if (shutdownViaSpout) {
        logger.info("Requesting stop via Spout.isCompleted()");
        mockSpout.completed = true;
    } else {
        logger.info("Requesting stop via SpoutRunner.requestStop()");
        spoutRunner.requestStop();
    }

    // Wait for thread to stop.
    await()
        .atMost(maxWaitTime * 2, TimeUnit.SECONDS)
        .until(future::isDone);

    // Make sure it actually stopped
    assertEquals("Should have no running threads", 0, executorService.getActiveCount());

    // verify close was called
    assertTrue("Close was called on our mock spout", mockSpout.wasCloseCalled);

    // Verify entries removed from buffer, ackQueue, failQueue
    verify(messageBus, times(1)).unregisterVirtualSpout(eq(virtualSpoutId));
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:79,代码来源:SpoutRunnerTest.java


注:本文中的java.time.Clock.systemUTC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。