本文整理汇总了Java中java.util.concurrent.TimeUnit.MILLISECONDS属性的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.MILLISECONDS属性的具体用法?Java TimeUnit.MILLISECONDS怎么用?Java TimeUnit.MILLISECONDS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.MILLISECONDS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDuplicationWithinCleanUpTimeout
@Test
public void testDuplicationWithinCleanUpTimeout() throws Exception {
final int timeout = 300;
final int collectionSize = 1;
DuplicationDetector instance = new DuplicationDetector(TimeUnit.MILLISECONDS, timeout, collectionSize, Executors.newSingleThreadScheduledExecutor());
final int cleanupInterval = 100;
instance.setCleanDelayMili(cleanupInterval);
instance.start();
try {
CoapPacket packet = mock(CoapPacket.class);
when(packet.getRemoteAddress()).thenReturn(InetSocketAddress.createUnresolved("testHost", 8080));
when(packet.getMessageId()).thenReturn(9);
CoapPacket firstIsDuplicated = instance.isMessageRepeated(packet);
Thread.sleep(cleanupInterval + 1);
CoapPacket secondIsDuplicated = instance.isMessageRepeated(packet);
assertNull("insertion to empty duplicate check list fails", firstIsDuplicated);
assertNotNull("second insertion within timeout with same id succeeds", secondIsDuplicated);
} finally {
instance.stop();
}
}
示例2: create
public HttpClientConnectionManager create(ApacheSdkHttpClientFactory configuration,
AttributeMap standardOptions) {
ConnectionSocketFactory sslsf = getPreferredSocketFactory(standardOptions);
final PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager(
createSocketFactoryRegistry(sslsf),
null,
DefaultSchemePortResolver.INSTANCE,
null,
configuration.connectionTimeToLive().orElse(Defaults.CONNECTION_POOL_TTL).toMillis(),
TimeUnit.MILLISECONDS);
cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
cm.setDefaultSocketConfig(buildSocketConfig(standardOptions));
return cm;
}
示例3: open
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
initialized = false;
this.context = context;
// Spout internals
this.collector = collector;
numUncommittedOffsets = 0;
// Offset management
firstPollOffsetStrategy = kafkaSpoutConfig.getFirstPollOffsetStrategy();
// with AutoCommitMode, offset will be periodically committed in the background by Kafka consumer
// consumerAutoCommitMode = kafkaSpoutConfig.isConsumerAutoCommitMode();
//永远设置为false
consumerAutoCommitMode = false;
// Retries management
retryService = kafkaSpoutConfig.getRetryService();
if (!consumerAutoCommitMode) { // If it is auto commit, no need to commit offsets manually
commitTimer = new Timer(TIMER_DELAY_MS, kafkaSpoutConfig.getOffsetsCommitPeriodMs(), TimeUnit.MILLISECONDS);
}
refreshSubscriptionTimer = new Timer(TIMER_DELAY_MS, kafkaSpoutConfig.getPartitionRefreshPeriodMs(), TimeUnit.MILLISECONDS);
acked = new HashMap<>();
emitted = new HashSet<>();
waitingToEmit = Collections.emptyListIterator();
LOG.info("Kafka Spout opened with the following configuration: {}", kafkaSpoutConfig);
}
示例4: toTimeUnit
/**
* Convert a protocol buffer TimeUnit to a client TimeUnit
* @param proto
* @return the converted client TimeUnit
*/
public static TimeUnit toTimeUnit(final HBaseProtos.TimeUnit proto) {
switch (proto) {
case NANOSECONDS:
return TimeUnit.NANOSECONDS;
case MICROSECONDS:
return TimeUnit.MICROSECONDS;
case MILLISECONDS:
return TimeUnit.MILLISECONDS;
case SECONDS:
return TimeUnit.SECONDS;
case MINUTES:
return TimeUnit.MINUTES;
case HOURS:
return TimeUnit.HOURS;
case DAYS:
return TimeUnit.DAYS;
default:
throw new RuntimeException("Invalid TimeUnit " + proto);
}
}
示例5: init
/**
* Initial MiniDownloader.
*
* @param context
*/
public void init(Context context) {
this.appContext = context.getApplicationContext();
/** Create work executor. */
this.workExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(), 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>()) {
@Override
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
if (callable instanceof CustomFutureCallable) {
return ((CustomFutureCallable) callable).newTaskFor();
}
return super.newTaskFor(callable);
}
};
/** Create command executor. */
this.commandExecutor = Executors.newSingleThreadExecutor();
/** Create and initial task manager. */
taskManager = new TaskManager();
taskManager.init(context);
/** Create and start ProgressUpdater. */
progressUpdater = new ProgressUpdater();
progressUpdater.start();
}
示例6: testEqualsMethodReflexivity
@Test
public void testEqualsMethodReflexivity() {
FakeLoad child1 = new SimpleFakeLoad(5, TimeUnit.SECONDS);
FakeLoad child2 = new SimpleFakeLoad(500, TimeUnit.MILLISECONDS);
FakeLoad child3 = new SimpleFakeLoad(1, TimeUnit.MINUTES);
// test reflexivity
assertEqualsReflexivity(fakeload);
fakeload = fakeload.lasting(300, TimeUnit.MILLISECONDS).repeat(3)
.withCpu(50)
.withMemory(300, MemoryUnit.MB)
.withDiskInput(5000, MemoryUnit.BYTES);
assertEqualsReflexivity(fakeload);
fakeload = fakeload.lasting(30, TimeUnit.SECONDS).repeat(6)
.withCpu(80)
.withMemory(300, MemoryUnit.KB)
.withDiskInput(51200, MemoryUnit.BYTES)
.addLoad(child1).addLoad(child2).addLoad(child3);
assertEqualsReflexivity(fakeload);
}
示例7: test
@Test
public void test() {
int threads = 40;
ThreadPoolExecutor executor = new ThreadPoolExecutor(threads, threads, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
try {
int jobs = 1000;
int add = 1000;
latch = new CountDownLatch(jobs);
for (int i = 0; i < jobs; ++i) {
executor.execute(new IncReadDecValueAsync(add));
}
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted.", e);
}
log.info("Checking value, expecting 0 ...");
if (value != 0) {
testFailed("value == " + value + " != 0");
}
testOk();
} finally {
executor.shutdownNow();
}
}
示例8: BlockingExecutor
/**
* Creates a BlockingExecutor which will block and prevent further
* submission to the pool when the specified queue size has been reached.
*
* @param poolSize the number of the threads in the pool
* @param queueSize the size of the queue
*/
public BlockingExecutor(final int poolSize, final int queueSize) {
super(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
// the semaphore is bounding both the number of tasks currently executing
// and those queued up
semaphore = new Semaphore(poolSize + queueSize);
}
示例9: init
@Override
public void init() throws EventException {
//Configure the QueueController-EventService connector
eventConnector = new QueueControllerEventConnector();
eventConnector.setEventService(eservice);
eventConnector.setUri(uri);
resultHandler = new ExceptionHandler() {
@Override
public Logger getLogger() {
return logger;
}
};
//Set up requester to handle remote requests
requester = eservice.createRequestor(uri,
IQueueService.QUEUE_REQUEST_TOPIC,
IQueueService.QUEUE_RESPONSE_TOPIC);
long timeout = Long.getLong("org.eclipse.scanning.event.remote.queueControllerServiceTimeout", 5000);
logger.debug("Setting timeout {} {}" , timeout , " ms");
ResponseConfiguration conf = new ResponseConfiguration( ResponseType.ONE,
timeout,
TimeUnit.MILLISECONDS);
requester.setResponseConfiguration(conf);
}
示例10: startMDSListenServer
private void startMDSListenServer() {
boolean isStartMDFListener = DataConvertHelper
.toBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "http.enable"), false);
if (isStartMDFListener == true) {
// start MDFListenServer
int port = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"));
int backlog = Integer
.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"));
int core = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"));
int max = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"));
int bqsize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"));
mdfListenServer = new MDFListenServer("MDFListenServer", this.feature, "mdfhandlers");
@SuppressWarnings({ "rawtypes", "unchecked" })
ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue(bqsize));
mdfListenServer.start(exe, port, backlog);
if (log.isTraceEnable()) {
log.info(this, "MDFListenServer started");
}
}
}
示例11: TimeValue
public TimeValue(long millis) {
this(millis, TimeUnit.MILLISECONDS);
}
示例12: StressAddMultiThreadedTest
public StressAddMultiThreadedTest() {
queue = new ArrayBlockingQueue<>(THREADS);
executor = new ThreadPoolExecutor(THREADS, THREADS, 100,
TimeUnit.MILLISECONDS, queue,
new ThreadPoolExecutor.CallerRunsPolicy());
}
示例13: appNamespaceCacheScanIntervalTimeUnit
@Override
public TimeUnit appNamespaceCacheScanIntervalTimeUnit() {
return TimeUnit.MILLISECONDS;
}
示例14: getConfigCacheExpireTimeUnit
@Override
public TimeUnit getConfigCacheExpireTimeUnit() {
return TimeUnit.MILLISECONDS;
}
示例15: StandardThreadExecutor
public StandardThreadExecutor(int coreThreads, int maxThreads, int queueCapacity,
ThreadFactory threadFactory) {
this(coreThreads, maxThreads, DEFAULT_MAX_IDLE_TIME, TimeUnit.MILLISECONDS, queueCapacity,
threadFactory);
}