當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。