本文整理汇总了Java中co.paralleluniverse.strands.Strand.sleep方法的典型用法代码示例。如果您正苦于以下问题:Java Strand.sleep方法的具体用法?Java Strand.sleep怎么用?Java Strand.sleep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类co.paralleluniverse.strands.Strand
的用法示例。
在下文中一共展示了Strand.sleep方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sleepImpl
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
/**
* This method is used by both sleep() methods to implement sleeping
* for the given time even if interrupted
*
* @param millis the number of milliseconds to sleep
* @param closure optional closure called when interrupted
* as long as the closure returns false the sleep continues
*/
private static void sleepImpl(long millis, Closure closure) throws SuspendExecution{
long start = System.currentTimeMillis();
long rest = millis;
long current;
while (rest > 0) {
try {
Strand.sleep(rest);
rest = 0;
} catch (InterruptedException e) {
if (closure != null) {
if (DefaultTypeTransformation.castToBoolean(closure.call(e))) {
return;
}
}
current = System.currentTimeMillis(); // compensate for closure's time
rest = millis + start - current;
}
}
}
示例2: getFiber
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
private static Fiber getFiber(final long sleep, final String message) {
return new Fiber<String>() {
@Override
protected String run() throws SuspendExecution, InterruptedException {
Strand.sleep(sleep);
return message;
}
};
}
示例3: sleep
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
@Suspendable
public void sleep() {
try {
Strand.sleep(1, TimeUnit.SECONDS);
} catch (SuspendExecution | InterruptedException e) {
e.printStackTrace();
}
}
示例4: sleepIfOnRetry
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
private static long sleepIfOnRetry(final String logMethodName, final Name tableName, final int attemptCount, final long currentRetryDelay, final ResourceConnectTolerance rct) {
long nextRetryDelay;
/*
* If this is the first attempt, proceed immediately. Otherwise, delay by the current
* exponential-backoff delay interval, then apply the exponential backoff for the next
* interval (if it becomes necessary)
*/
if (attemptCount == 0) {
nextRetryDelay = rct.getRetryDelayInit();
} else {
LOG.debug(logMethodName,
()->"Table '",
()->tableName,
()->"' connection attempt ",
()->Integer.toString(attemptCount),
()->"/",
()->Integer.toString(rct.getAttemptsMax()),
()->" failed; retrying in ",
()->Long.toString(currentRetryDelay),
()->"ms...");
try {
Strand.sleep(currentRetryDelay);
} catch (InterruptedException iExc) {
// ignore
} catch (SuspendExecution quasarInstrumentationExcNeverThrown) {
throw new AssertionError(quasarInstrumentationExcNeverThrown);
}
nextRetryDelay = currentRetryDelay * rct.getRetryDelayMultiplier();
nextRetryDelay = Math.min(rct.getRetryDelayMax(), nextRetryDelay);
}
return nextRetryDelay;
}
示例5: linkToEchoService
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
void linkToEchoService(Actor ax) throws SuspendExecution, InterruptedException{
Message cmsg = new Message();
while (true){
ax.monitor(echoSvcAid);
Message msg = ax.recv(cmsg, AtomCode.EXIT, AtomCode.MONITOR);
if (AtomCode.equals(msg.getType(), AtomCode.MONITOR)){
break;
}
Strand.sleep(10);
}
}
示例6: main
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
public static void main(final ApplicationContext applicationContext, int tn)
throws SuspendExecution, InterruptedException, ExecutionException {
final AtomicInteger total = new AtomicInteger(0);
long start = System.currentTimeMillis();
System.out.println("==============");
int i = 0;
while (i++ < tn) {
Fiber f = new Fiber<Void>() {
private static final long serialVersionUID = 1L;
@Override
protected Void run() throws SuspendExecution, InterruptedException {
int k = 0;
while (k++ < 10) {
DataSourceProxy phoenixDS = (DataSourceProxy) applicationContext.getBean("phoenixDS");
excuteQuery(phoenixDS, "select count(1) from metric_data_entity_pt1m_2");
}
total.addAndGet(10);
return super.run();
}
};
f.start();
}
while (total.get() < tn * 10) {
Strand.sleep(2);
}
System.out.println("F" + (System.currentTimeMillis() - start));
}
示例7: main
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
public static void main(final ApplicationContext applicationContext, int tn)
throws SuspendExecution, InterruptedException {
final ThreadPoolExecutor pool = new ThreadPoolExecutor(4, 1000, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
final AtomicInteger total = new AtomicInteger(0);
long start = System.currentTimeMillis();
System.out.println("==============");
int i = 0;
while (i++ < tn)
pool.submit(new Runnable() {
@Override
public void run() {
int k = 0;
while (k++ < 10) {
DataSourceProxy phoenixDS = (DataSourceProxy) applicationContext.getBean("phoenixDS");
excuteQuery(phoenixDS, "select count(1) from metric_data_entity_pt1m_2");
}
total.addAndGet(10);
}
});
while (total.get() < tn * 10) {
Strand.sleep(2);
}
System.out.println("T" + (System.currentTimeMillis() - start));
pool.shutdown();
}
示例8: call
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
@Override
@Suspendable
public String call() throws Exception {
Strand.sleep(sleep);
return message;
}
示例9: execute
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
@Override
public Void execute(final long nanoTime, final Q request) throws SuspendExecution, InterruptedException {
Strand.sleep(sleepMillis, sleepNanos);
return null;
}
示例10: sleep
import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
/**
* Causes the currently executing strand to sleep (temporarily cease
* execution) for the specified number of milliseconds, subject to
* the precision and accuracy of system timers and schedulers.
*
* @param millis the length of time to sleep in milliseconds
* @throws IllegalArgumentException if the value of {@code millis} is negative
* @throws InterruptedException if any strand has interrupted the current strand. The
* <i>interrupted status</i> of the current strand is
* cleared when this exception is thrown.
*/
public static void sleep(long millis) throws InterruptedException {
try {
Strand.sleep(millis);
} catch (SuspendExecution e) {
throw RuntimeSuspendExecution.of(e);
}
}