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


Java TimeUnit.convert方法代码示例

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


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

示例1: lockInterruptibly

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException {
    long waitTime = -1;
    if (leaseTime == -1) {
        waitTime = 5;
        unit = TimeUnit.SECONDS;
    } else {
        waitTime = unit.toMillis(leaseTime);
        if (waitTime <= 2000) {
            waitTime = 2000;
        } else if (waitTime <= 5000) {
            waitTime = ThreadLocalRandom.current().nextLong(waitTime/2, waitTime);
        } else {
            waitTime = ThreadLocalRandom.current().nextLong(5000, waitTime);
        }
        waitTime = unit.convert(waitTime, TimeUnit.MILLISECONDS);
    }
    
    while (true) {
        if (tryLock(waitTime, leaseTime, unit)) {
            return;
        }
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:24,代码来源:RedissonMultiLock.java

示例2: to

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
static void to(long v, TimeUnit unit) {
    FileTime t = FileTime.from(v, unit);
    for (TimeUnit u: TimeUnit.values()) {
        long result = t.to(u);
        long expected = u.convert(v, unit);
        if (result != expected) {
            throw new RuntimeException("unexpected result");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Basic.java

示例3: getDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/**
 * Method that returns the remaining time to the activation of the event
 */
@Override
public long getDelay(TimeUnit unit) {
	Date now = new Date();
	long diff = startDate.getTime() - now.getTime();
	return unit.convert(diff, TimeUnit.MILLISECONDS);
}
 
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:10,代码来源:Event.java

示例4: parse

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public static long parse(String value, TimeUnit timeUnit) {
    try {
        return timeUnit.convert(Long.parseLong(value), TimeUnit.MILLISECONDS);
    } catch (NumberFormatException e) {
        long millis = PARSER.parsePeriod(value.replace(" ", "")).toStandardDuration().getMillis();
        return timeUnit.convert(millis, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:9,代码来源:TimeUnitParser.java

示例5: getKeepAliveDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public long getKeepAliveDelay(TimeUnit unit) {
    return unit.convert(keepAliveDelayNanos, TimeUnit.NANOSECONDS);
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:4,代码来源:Config.java

示例6: getDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public long getDelay(TimeUnit unit)
{
    return unit.convert(trigger - System.nanoTime(), NANOSECONDS);
}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:6,代码来源:DelayQueueDemo.java

示例7: getMaxTransactionTime

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public long getMaxTransactionTime(TimeUnit timeUnit) {
    return timeUnit.convert(maxTransactionTimeMillis, TimeUnit.MILLISECONDS);
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:4,代码来源:QueuedSiteToSiteClientConfig.java

示例8: getTimeout

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public long getTimeout(final TimeUnit timeUnit) {
    return timeUnit.convert(sslSocketChannel.getTimeout(), TimeUnit.MILLISECONDS);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:5,代码来源:SSLCommsSession.java

示例9: get

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public V get(long timeout, TimeUnit unit) throws InterruptedException,
		ExecutionException, TimeoutException {
	int timeoutInMillis = (int) unit.convert(timeout, TimeUnit.MILLISECONDS);
	return (V)invokeFuture.get(timeoutInMillis).getResult();
}
 
开发者ID:zhaoshiling1017,项目名称:voyage,代码行数:7,代码来源:FutureAdapter.java

示例10: getTimeout

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public long getTimeout(final TimeUnit timeUnit) {
    return timeUnit.convert(timeoutMillis, TimeUnit.MILLISECONDS);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:5,代码来源:StandardCommsSession.java

示例11: now

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
default long now(TimeUnit unit) {
    return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:4,代码来源:SchedulerService.java

示例12: getDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
@Override
public long getDelay(@NonNull TimeUnit timeUnit) {
    return timeUnit.convert(delayInMillis - (System.currentTimeMillis() - origin), TimeUnit.MILLISECONDS);
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:5,代码来源:Average.java

示例13: tryLock

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {
    long newLeaseTime = -1;
    if (leaseTime != -1) {
        newLeaseTime = waitTime*2;
    }
    
    long time = System.currentTimeMillis();
    long remainTime = -1;
    if (waitTime != -1) {
        remainTime = unit.toMillis(waitTime);
    }
    int failedLocksLimit = failedLocksLimit();
    List<RLock> lockedLocks = new ArrayList<RLock>(locks.size());
    for (ListIterator<RLock> iterator = locks.listIterator(); iterator.hasNext();) {
        RLock lock = iterator.next();
        boolean lockAcquired;
        try {
            if (waitTime == -1 && leaseTime == -1) {
                lockAcquired = lock.tryLock();
            } else {
                long awaitTime = unit.convert(remainTime, TimeUnit.MILLISECONDS);
                lockAcquired = lock.tryLock(awaitTime, newLeaseTime, unit);
            }
        } catch (Exception e) {
            lockAcquired = false;
        }
        
        if (lockAcquired) {
            lockedLocks.add(lock);
        } else {
            if (locks.size() - lockedLocks.size() == failedLocksLimit()) {
                break;
            }

            if (failedLocksLimit == 0) {
                unlockInner(lockedLocks);
                if (waitTime == -1 && leaseTime == -1) {
                    return false;
                }
                failedLocksLimit = failedLocksLimit();
                lockedLocks.clear();
                // reset iterator
                while (iterator.hasPrevious()) {
                    iterator.previous();
                }
            } else {
                failedLocksLimit--;
            }
        }
        
        if (remainTime != -1) {
            remainTime -= (System.currentTimeMillis() - time);
            time = System.currentTimeMillis();
            if (remainTime <= 0) {
                unlockInner(lockedLocks);
                return false;
            }
        }
    }

    if (leaseTime != -1) {
        List<RFuture<Boolean>> futures = new ArrayList<RFuture<Boolean>>(lockedLocks.size());
        for (RLock rLock : lockedLocks) {
            RFuture<Boolean> future = rLock.expireAsync(unit.toMillis(leaseTime), TimeUnit.MILLISECONDS);
            futures.add(future);
        }
        
        for (RFuture<Boolean> rFuture : futures) {
            rFuture.syncUninterruptibly();
        }
    }
    
    return true;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:75,代码来源:RedissonMultiLock.java

示例14: getDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
/** Get the delay until this event should happen. */
@Override
public long getDelay(final TimeUnit unit) {
  final long millisLeft = renewalTime - Time.now();
  return unit.convert(millisLeft, TimeUnit.MILLISECONDS);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:7,代码来源:DelegationTokenRenewer.java

示例15: getDelay

import java.util.concurrent.TimeUnit; //导入方法依赖的package包/类
public long getDelay(TimeUnit unit) {
  return unit.convert(this.expirationTime - EnvironmentEdgeManager.currentTime(),
      TimeUnit.MILLISECONDS);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:5,代码来源:Leases.java


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