@Override protected Integer run() throws SuspendExecution, InterruptedException { System.out.println("Hello world2!"); Fiber.sleep(1000); System.out.println("Hello world3!"); return 2; } }.start();
@Override public Integer run() throws SuspendExecution, InterruptedException { Fiber.sleep(1000); fiber1ToFiber2.send(1); Integer i1 = fiber2ToFiber1.receive(); System.out.println(" Hello words " + i1); fiber1ToFiber2.send(9); Integer i2 = fiber2ToFiber1.receive(); System.out.println(" Hello words " + i2); fiber1ToFiber2.send(0); return i2; } }).start();
@Override public void await(long timeInMilliseconds) throws InterruptedException { if(timeInMilliseconds > 0){ try { Fiber.sleep(timeInMilliseconds); } catch (SuspendExecution e) { // this is not a real exception // leave this method without instrumentation should be fine } } }
public static void sleep(long millis) throws InterruptedException, SuspendExecution { sleep(millis, TimeUnit.MILLISECONDS); }
public static void sleep(long millis, int nanos) throws InterruptedException, SuspendExecution { sleep(TimeUnit.MILLISECONDS.toNanos(millis) + nanos, TimeUnit.NANOSECONDS); }
public static void sleep(long millis) throws InterruptedException { try { Fiber.sleep(millis); } catch (SuspendExecution e) { throw RuntimeSuspendExecution.of(e); } }
public static void sleep(long millis, int nanos) throws InterruptedException { try { Fiber.sleep(millis, nanos); } catch (SuspendExecution e) { throw RuntimeSuspendExecution.of(e); } }
public static void sleep(long millis) throws SuspendExecution, InterruptedException { if (Fiber.currentFiber() != null) Fiber.sleep(millis); else Thread.sleep(millis); }
public static void sleep(long duration, TimeUnit unit) throws InterruptedException { try { Fiber.sleep(duration, unit); } catch (SuspendExecution e) { throw RuntimeSuspendExecution.of(e); } }
/** * 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 SuspendExecution, InterruptedException { if (isCurrentFiber()) Fiber.sleep(millis); else Thread.sleep(millis); }
/** * Causes the currently executing strand to sleep (temporarily cease * execution) for the specified duration, subject to * the precision and accuracy of system timers and schedulers. * * @param duration the length of time to sleep in the time unit specified by {@code unit}. * @param unit the time unit of {@code duration}. * * @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 duration, TimeUnit unit) throws SuspendExecution, InterruptedException { if (isCurrentFiber()) Fiber.sleep(duration, unit); else unit.sleep(duration); }
/** * Causes the currently executing strand to sleep (temporarily cease * execution) for the specified number of milliseconds plus the specified * number of nanoseconds, subject to the precision and accuracy of system * timers and schedulers. * * @param millis the length of time to sleep in milliseconds * @param nanos {@code 0-999999} additional nanoseconds to sleep * * @throws IllegalArgumentException if the value of {@code millis} is negative, * or the value of {@code nanos} is not in the range {@code 0-999999} * @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, int nanos) throws SuspendExecution, InterruptedException { if (isCurrentFiber()) Fiber.sleep(millis, nanos); else Thread.sleep(millis, nanos); }