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


Java Strand.sleep方法代码示例

本文整理汇总了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;
		}
	}
}
 
开发者ID:dinix2008,项目名称:quasar-groovy,代码行数:28,代码来源:DefaultGroovyStaticMethods.java

示例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;
        }
    };
}
 
开发者ID:pmohankumar,项目名称:fibers,代码行数:10,代码来源:FiberTest.java

示例3: sleep

import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
@Suspendable
public void sleep() {
    try {
        Strand.sleep(1, TimeUnit.SECONDS);
    } catch (SuspendExecution | InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:pesia,项目名称:vertx-sync-examples,代码行数:9,代码来源:FiberHttpServer.java

示例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;
}
 
开发者ID:LiaisonTechnologies,项目名称:shachi,代码行数:34,代码来源:HBaseUtil.java

示例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);
	}
}
 
开发者ID:nousxiong,项目名称:actorx4j,代码行数:12,代码来源:ServiceExit.java

示例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));
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:30,代码来源:Quasar.java

示例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();
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:30,代码来源:Quasar2.java

示例8: call

import co.paralleluniverse.strands.Strand; //导入方法依赖的package包/类
@Override
@Suspendable
public String call() throws Exception {
    Strand.sleep(sleep);
    return message;
}
 
开发者ID:pmohankumar,项目名称:fibers,代码行数:7,代码来源:FiberCallable.java

示例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;
}
 
开发者ID:pinterest,项目名称:jbender,代码行数:6,代码来源:SleepyRequestExecutor.java

示例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);
    }
}
 
开发者ID:icode,项目名称:ameba,代码行数:19,代码来源:Strands.java


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