Class Fiber<V>
- java.lang.Object
- 
- co.paralleluniverse.strands.Strand
- 
- co.paralleluniverse.fibers.Fiber<V>
 
 
- 
- Type Parameters:
- V- The type of the fiber's result value. Should be set to- Voidif no value is to be returned by the fiber.
 - All Implemented Interfaces:
- Joinable<V>,- java.io.Serializable,- java.util.concurrent.Future<V>
 
 public class Fiber<V> extends Strand implements Joinable<V>, java.io.Serializable, java.util.concurrent.Future<V> A lightweight thread.There are two ways to create a new fiber: either subclass the Fiberclass and override therunmethod, or pass the code to be executed in the fiber as thetargetparameter to the constructor. All in all, the Fiber API resembles theThreadclass in many ways.A fiber runs inside a ForkJoinPool. A Fiber can be serialized if it's not running and all involved classes and data types are also Serializable.A new Fiber occupies under 400 bytes of memory (when using the default stack size, and compressed OOPs are turned on, as they are by default). - See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class co.paralleluniverse.strands.StrandStrand.State, Strand.UncaughtExceptionHandler
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_STACK_SIZEprotected static co.paralleluniverse.common.monitoring.FlightRecorderflightRecorder- 
Fields inherited from class co.paralleluniverse.strands.StrandcurrentStrand, MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
- 
 - 
Constructor SummaryConstructors Constructor Description Fiber()Creates a new child Fiber subclassing the Fiber class and overriding therunmethod.Fiber(Fiber fiber, FiberScheduler scheduler, SuspendableCallable<V> target)Fiber(Fiber fiber, FiberScheduler scheduler, SuspendableRunnable target)Fiber(Fiber fiber, SuspendableCallable<V> target)Fiber(Fiber fiber, SuspendableRunnable target)Fiber(FiberScheduler scheduler)Creates a new Fiber subclassing the Fiber class and overriding therunmethod.Fiber(FiberScheduler scheduler, SuspendableCallable<V> target)Creates a new Fiber from the givenSuspendableCallable.Fiber(FiberScheduler scheduler, SuspendableRunnable target)Creates a new Fiber from the given SuspendableRunnable.Fiber(SuspendableCallable<V> target)Creates a new child Fiber from the givenSuspendableCallable.Fiber(SuspendableRunnable target)Creates a new child Fiber from the givenSuspendableRunnable.Fiber(java.lang.String name)Creates a new child Fiber subclassing the Fiber class and overriding therunmethod.Fiber(java.lang.String name, int stackSize)Creates a new child Fiber subclassing the Fiber class and overriding therunmethod.Fiber(java.lang.String name, int stackSize, SuspendableCallable<V> target)Creates a new fiber from the givenSuspendableCallablescheduled in thedefault fiber schedulerFiber(java.lang.String name, int stackSize, SuspendableRunnable target)Creates a new child Fiber from the givenSuspendableRunnable.Fiber(java.lang.String name, FiberScheduler scheduler)Creates a new Fiber subclassing the Fiber class and overriding therunmethod.Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize)Creates a new Fiber subclassing the Fiber class and overriding therunmethod.Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize, SuspendableCallable<V> target)Creates a new fiber from the givenSuspendableCallable.Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize, SuspendableRunnable target)Creates a new Fiber from the givenSuspendableRunnable.Fiber(java.lang.String name, FiberScheduler scheduler, SuspendableCallable<V> target)Creates a new Fiber from the givenSuspendableCallable.Fiber(java.lang.String name, FiberScheduler scheduler, SuspendableRunnable target)Creates a new Fiber from the givenSuspendableRunnable.Fiber(java.lang.String name, SuspendableCallable<V> target)Creates a new child Fiber from the givenSuspendableCallable.Fiber(java.lang.String name, SuspendableRunnable target)Creates a new child Fiber from the givenSuspendableRunnable.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)static FibercurrentFiber()Returns the active Fiber on this thread or NULL if no Fiber is running.static voiddumpStack()booleanequals(java.lang.Object obj)Vget()Vget(long timeout, java.util.concurrent.TimeUnit unit)java.lang.ObjectgetBlocker()Returns the blocker object supplied to the most recent invocation of aparkmethod that has not yet unblocked, or null if not blocked.static longgetCurrentRun()static Strand.UncaughtExceptionHandlergetDefaultUncaughtExceptionHandler()Returns the default handler invoked when a fiber abruptly terminates due to an uncaught exception.static co.paralleluniverse.io.serialization.ByteArraySerializergetFiberSerializer()Returns aByteArraySerializercapable of serializing an object graph containing fibers.static co.paralleluniverse.io.serialization.ByteArraySerializergetFiberSerializer(boolean includeThreadLocals)Returns aByteArraySerializercapable of serializing an object graph containing fibers.longgetId()Returns the strand's id.java.lang.InterruptedExceptiongetInterruptStack()Returns anInterruptedExceptionthat was created when theStrand.interrupt()method was called, and can be used to retrieve the stack trace of the strand that interrupted this strand.co.paralleluniverse.fibers.FibersMonitorgetMonitor()java.lang.StringgetName()Returns the strand's name.booleangetNoLocals()Deprecated.intgetPriority()Returns this fiber's priority.FiberSchedulergetScheduler()java.lang.StackTraceElement[]getStackTrace()Returns an array of stack trace elements representing the stack dump of this strand.Strand.StategetState()Returns the strand's current running state.SuspendableCallable<V>getTarget()java.lang.ObjectgetTask()Strand.UncaughtExceptionHandlergetUncaughtExceptionHandler()Returns the handler invoked when this fiber abruptly terminates due to an uncaught exception.java.lang.ObjectgetUnderlying()Returns the underlying object of this strand, namely aThreador aFiber.inthashCode()FiberinheritThreadLocals()Causes the current strand'sthread-localsto be inherited by this fiber.voidinterrupt()Interrupts this strand.static booleaninterrupted()booleanisAlive()Tests whether this strand is alive, namely it has been started but not yet terminated.booleanisCancelled()static booleanisCurrentFiber()Tests whether current code is executing in a fiber.booleanisDone()booleanisFiber()Tests whether this strand is a fiber.booleanisInterrupted()Tests whether this strand has been interrupted.protected booleanisRecordingLevel(int level)booleanisTerminated()Tests whether this strand has terminated.voidjoin()Awaits the termination of this strand.voidjoin(long timeout, java.util.concurrent.TimeUnit unit)Awaits the termination of this strand, at most for the timeout duration specified.Fiber<V>joinNoSuspend()Fiber<V>joinNoSuspend(long timeout, java.util.concurrent.TimeUnit unit)protected voidonCompletion()protected voidonException(java.lang.Throwable t)protected voidonParked()protected voidonResume()static voidpark()static voidpark(long timeout, java.util.concurrent.TimeUnit unit)static voidpark(java.lang.Object blocker)static booleanpark(java.lang.Object blocker, long timeout, java.util.concurrent.TimeUnit unit)static voidparkAndCustomSerialize(CustomFiberWriter writer)Parks the fiber and allows the given callback to serialize it, optimized for use cases where the callback object has a custom way to obtain the required serializer (e.g.static voidparkAndSerialize(FiberWriter writer)Parks the fiber and allows the given callback to serialize it.static voidparkAndUnpark(Fiber other)static voidparkAndUnpark(Fiber other, java.lang.Object blocker)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object... args)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6)protected voidrecord(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7)protected Vrun()static voidsetDefaultUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh)Set the default handler invoked when a fiber abruptly terminates due to an uncaught exception, and no other handler has been defined for that fiber.Fiber<V>setName(java.lang.String name)Sets this strand's name.FibersetNoLocals(boolean value)Deprecated.FibersetPriority(int newPriority)Sets the priority of this fiber.voidsetUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh)Set the handler invoked when this fiber abruptly terminates due to an uncaught exception.protected booleanshouldPreempt(int type)static voidsleep(long millis)static voidsleep(long millis, int nanos)static voidsleep(long duration, java.util.concurrent.TimeUnit unit)Fiber<V>start()Starts the strand.java.lang.StringtoString()voidunpark()Makes available the permit for this fiber, if it was not already available.voidunpark(java.lang.Object unblocker)Makes available the permit for this strand, if it was not already available.static <V> Fiber<V>unparkDeserialized(Fiber<V> f, FiberScheduler scheduler)Unparks a fiber that's been deserialized (with the help ofgetFiberSerializer()static <V> Fiber<V>unparkSerialized(byte[] serFiber, FiberScheduler scheduler)Deserializes a fiber from the given byte array and unparks it.static voidyield()static voidyieldAndUnpark(Fiber other)static voidyieldAndUnpark(Fiber other, java.lang.Object blocker)- 
Methods inherited from class co.paralleluniverse.strands.Strandclone, clone, currentStrand, equals, join, join, of, of, of, parkAndUnpark, parkAndUnpark, parkNanos, parkNanos, parkUntil, printStackTrace, printStackTrace, toRunnable, toRunnable, toString, unpark, unpark, unpark, unwrapSuspendable, yieldAndUnpark, yieldAndUnpark
 
- 
 
- 
- 
- 
Field Detail- 
DEFAULT_STACK_SIZEpublic static final int DEFAULT_STACK_SIZE - See Also:
- Constant Field Values
 
 - 
flightRecorderprotected static final co.paralleluniverse.common.monitoring.FlightRecorder flightRecorder 
 
- 
 - 
Constructor Detail- 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize, SuspendableCallable<V> target)Creates a new fiber from the givenSuspendableCallable.- Parameters:
- name- The name of the fiber (may be- null)
- scheduler- The- FiberSchedulerthat will schedule the fiber.
- stackSize- the initial size of the data stack.
- target- the- SuspendableCallablefor the fiber. May- nullif the- runmethod is overriden.
 
 - 
Fiberpublic Fiber(java.lang.String name, int stackSize, SuspendableCallable<V> target)Creates a new fiber from the givenSuspendableCallablescheduled in thedefault fiber scheduler- Parameters:
- name- The name of the fiber (may be- null)
- stackSize- the initial size of the data stack.
- target- the- SuspendableCallablefor the fiber. May- nullif the- runmethod is overriden.
 
 - 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler, SuspendableCallable<V> target)Creates a new Fiber from the givenSuspendableCallable. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- scheduler- The scheduler pool in which the fiber should run.
- target- the SuspendableCallable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(FiberScheduler scheduler, SuspendableCallable<V> target) Creates a new Fiber from the givenSuspendableCallable. The new fiber has no name, and uses the default initial stack size.- Parameters:
- scheduler- The scheduler pool in which the fiber should run.
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize, SuspendableRunnable target)Creates a new Fiber from the givenSuspendableRunnable.- Parameters:
- name- The name of the fiber (may be null)
- scheduler- The scheduler pool in which the fiber should run.
- stackSize- the initial size of the data stack.
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler, SuspendableRunnable target)Creates a new Fiber from the givenSuspendableRunnable. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- scheduler- The scheduler pool in which the fiber should run.
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(FiberScheduler scheduler, SuspendableRunnable target) Creates a new Fiber from the given SuspendableRunnable. The new fiber has no name, and uses the default initial stack size.- Parameters:
- scheduler- The scheduler pool in which the fiber should run.
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler, int stackSize)Creates a new Fiber subclassing the Fiber class and overriding therunmethod.- Parameters:
- name- The name of the fiber (may be null)
- scheduler- The scheduler pool in which the fiber should run.
- stackSize- the initial size of the data stack.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, FiberScheduler scheduler)Creates a new Fiber subclassing the Fiber class and overriding therunmethod. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- scheduler- The scheduler pool in which the fiber should run.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(FiberScheduler scheduler) Creates a new Fiber subclassing the Fiber class and overriding therunmethod. The new fiber has no name, and uses the default initial stack size.- Parameters:
- scheduler- The scheduler pool in which the fiber should run.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, SuspendableCallable<V> target)Creates a new child Fiber from the givenSuspendableCallable. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(SuspendableCallable<V> target) Creates a new child Fiber from the givenSuspendableCallable. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber has no name, and uses the default initial stack size.- Parameters:
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, int stackSize, SuspendableRunnable target)Creates a new child Fiber from the givenSuspendableRunnable. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.- Parameters:
- name- The name of the fiber (may be null)
- stackSize- the initial size of the data stack.
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, SuspendableRunnable target)Creates a new child Fiber from the givenSuspendableRunnable. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(SuspendableRunnable target) Creates a new child Fiber from the givenSuspendableRunnable. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber has no name, and uses the default initial stack size.- Parameters:
- target- the SuspendableRunnable for the Fiber.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name, int stackSize)Creates a new child Fiber subclassing the Fiber class and overriding therunmethod. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber.- Parameters:
- name- The name of the fiber (may be null)
- stackSize- the initial size of the data stack.
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(java.lang.String name) Creates a new child Fiber subclassing the Fiber class and overriding therunmethod. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber uses the default initial stack size.- Parameters:
- name- The name of the fiber (may be null)
- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber() Creates a new child Fiber subclassing the Fiber class and overriding therunmethod. This constructor may only be called from within another fiber. This fiber will use the same fork/join pool as the creating fiber. The new fiber has no name, and uses the default initial stack size.- Throws:
- java.lang.NullPointerException- when proto is null
- java.lang.IllegalArgumentException- when stackSize is <= 0
 
 - 
Fiberpublic Fiber(Fiber fiber, SuspendableCallable<V> target) 
 - 
Fiberpublic Fiber(Fiber fiber, SuspendableRunnable target) 
 - 
Fiberpublic Fiber(Fiber fiber, FiberScheduler scheduler, SuspendableCallable<V> target) 
 - 
Fiberpublic Fiber(Fiber fiber, FiberScheduler scheduler, SuspendableRunnable target) 
 
- 
 - 
Method Detail- 
getTargetpublic final SuspendableCallable<V> getTarget() 
 - 
hashCodepublic final int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
equalspublic final boolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
getNamepublic final java.lang.String getName() Description copied from class:StrandReturns the strand's name.
 - 
setNamepublic final Fiber<V> setName(java.lang.String name) Description copied from class:StrandSets this strand's name. This method may only be called before the strand is started.
 - 
setPrioritypublic Fiber setPriority(int newPriority) Sets the priority of this fiber. The fiber priority's semantics - or even if it is ignored completely - is entirely up to the fiber's scheduler. The default fiber scheduler completely ignores fiber priority.- Specified by:
- setPriorityin class- Strand
- Parameters:
- newPriority- priority to set this fiber to
- Throws:
- java.lang.IllegalArgumentException- If the priority is not in the range- MIN_PRIORITYto- MAX_PRIORITY
- See Also:
- getPriority(),- Strand.MAX_PRIORITY,- Strand.MIN_PRIORITY
 
 - 
getPrioritypublic int getPriority() Returns this fiber's priority.- Specified by:
- getPriorityin class- Strand
- Returns:
- this strand's priority.
- See Also:
- setPriority(int)
 
 - 
getIdpublic long getId() Description copied from class:StrandReturns the strand's id. Id's are unique within a single JVM instance.
 - 
getTaskpublic java.lang.Object getTask() 
 - 
getSchedulerpublic FiberScheduler getScheduler() 
 - 
setNoLocals@Deprecated public Fiber setNoLocals(boolean value) Deprecated.
 - 
getNoLocals@Deprecated public boolean getNoLocals() Deprecated.
 - 
currentFiberpublic static Fiber currentFiber() Returns the active Fiber on this thread or NULL if no Fiber is running.- Returns:
- the active Fiber on this thread or NULL if no Fiber is running.
 
 - 
isCurrentFiberpublic static boolean isCurrentFiber() Tests whether current code is executing in a fiber. This method might be faster thanFiber.currentFiber() != null.- Returns:
- trueif called in a fiber;- falseotherwise.
 
 - 
getCurrentRunpublic static long getCurrentRun() 
 - 
isFiberpublic final boolean isFiber() Description copied from class:StrandTests whether this strand is a fiber.
 - 
getUnderlyingpublic final java.lang.Object getUnderlying() Description copied from class:StrandReturns the underlying object of this strand, namely aThreador aFiber.- Specified by:
- getUnderlyingin class- Strand
 
 - 
parkpublic static boolean park(java.lang.Object blocker, long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution- Throws:
- SuspendExecution
 
 - 
parkpublic static void park(java.lang.Object blocker) throws SuspendExecution- Throws:
- SuspendExecution
 
 - 
parkpublic static void park(long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution- Throws:
- SuspendExecution
 
 - 
parkpublic static void park() throws SuspendExecution- Throws:
- SuspendExecution
 
 - 
yieldpublic static void yield() throws SuspendExecution- Throws:
- SuspendExecution
 
 - 
parkAndUnparkpublic static void parkAndUnpark(Fiber other) throws SuspendExecution - Throws:
- SuspendExecution
 
 - 
parkAndUnparkpublic static void parkAndUnpark(Fiber other, java.lang.Object blocker) throws SuspendExecution - Throws:
- SuspendExecution
 
 - 
yieldAndUnparkpublic static void yieldAndUnpark(Fiber other, java.lang.Object blocker) throws SuspendExecution - Throws:
- SuspendExecution
 
 - 
yieldAndUnparkpublic static void yieldAndUnpark(Fiber other) throws SuspendExecution - Throws:
- SuspendExecution
 
 - 
sleeppublic static void sleep(long millis) throws java.lang.InterruptedException, SuspendExecution- Throws:
- java.lang.InterruptedException
- SuspendExecution
 
 - 
sleeppublic static void sleep(long millis, int nanos) throws java.lang.InterruptedException, SuspendExecution- Throws:
- java.lang.InterruptedException
- SuspendExecution
 
 - 
sleeppublic static void sleep(long duration, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, SuspendExecution- Throws:
- java.lang.InterruptedException
- SuspendExecution
 
 - 
interruptedpublic static boolean interrupted() 
 - 
getMonitorpublic co.paralleluniverse.fibers.FibersMonitor getMonitor() 
 - 
runprotected V run() throws SuspendExecution, java.lang.InterruptedException - Throws:
- SuspendExecution
- java.lang.InterruptedException
 
 - 
inheritThreadLocalspublic Fiber inheritThreadLocals() Causes the current strand'sthread-localsto be inherited by this fiber. By default onlyInheritableThreadLocals are inherited.This method must be called before the fiber is started (i.e. before the startmethod is called. Otherwise, anIllegalStateExceptionis thrown.- Returns:
- this
 
 - 
onParkedprotected void onParked() 
 - 
onResumeprotected void onResume() throws SuspendExecution, java.lang.InterruptedException- Throws:
- SuspendExecution
- java.lang.InterruptedException
 
 - 
shouldPreemptprotected boolean shouldPreempt(int type) 
 - 
onCompletionprotected void onCompletion() 
 - 
onExceptionprotected void onException(java.lang.Throwable t) 
 - 
interruptpublic final void interrupt() Description copied from class:StrandInterrupts this strand. If this strand is blocked, the blocking function will throw anInterruptedException. Otherwise, the strand may test its interrupted status with theStrand.interrupted()orStrand.isInterrupted()method.
 - 
isInterruptedpublic final boolean isInterrupted() Description copied from class:StrandTests whether this strand has been interrupted.- Specified by:
- isInterruptedin class- Strand
- Returns:
- trueif the strand has been interrupted;- falseotherwise.
- See Also:
- Strand.interrupt(),- Strand.interrupted()
 
 - 
getInterruptStackpublic final java.lang.InterruptedException getInterruptStack() Description copied from class:StrandReturns anInterruptedExceptionthat was created when theStrand.interrupt()method was called, and can be used to retrieve the stack trace of the strand that interrupted this strand. This method is only intended to assist in debugging. This method may returnnullif this information is not available. The current implementation always returnsnullif this strand is a thread.- Specified by:
- getInterruptStackin class- Strand
 
 - 
isAlivepublic final boolean isAlive() Description copied from class:StrandTests whether this strand is alive, namely it has been started but not yet terminated.
 - 
getStatepublic final Strand.State getState() Description copied from class:StrandReturns the strand's current running state.
 - 
isTerminatedpublic final boolean isTerminated() Description copied from class:StrandTests whether this strand has terminated.- Specified by:
- isTerminatedin class- Strand
 
 - 
getBlockerpublic final java.lang.Object getBlocker() Description copied from class:StrandReturns the blocker object supplied to the most recent invocation of aparkmethod that has not yet unblocked, or null if not blocked. The value returned is just a momentary snapshot -- the thread may have since unblocked or blocked on a different blocker object.- Specified by:
- getBlockerin class- Strand
- Returns:
- the blocker
 
 - 
unparkpublic final void unpark() Makes available the permit for this fiber, if it was not already available. If the fiber was blocked onparkthen it will unblock. Otherwise, its next call toparkis guaranteed not to block.
 - 
unparkpublic final void unpark(java.lang.Object unblocker) Description copied from class:StrandMakes available the permit for this strand, if it was not already available. If this strand was blocked onStrand.park()then it will unblock. Otherwise, its next call toStrand.park()is guaranteed not to block. This operation is not guaranteed to have any effect at all if the given strand has not been started.
 - 
join@Suspendable public final void join() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException Description copied from class:StrandAwaits the termination of this strand. This method blocks until this strand terminates.
 - 
join@Suspendable public final void join(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException Description copied from class:StrandAwaits the termination of this strand, at most for the timeout duration specified. This method blocks until this strand terminates or the timeout elapses.- Specified by:
- joinin interface- Joinable<V>
- Specified by:
- joinin class- Strand
- Parameters:
- timeout- the maximum duration to wait for the strand to terminate in the time unit specified by- unit.
- unit- the time unit of- timeout.
- Throws:
- java.util.concurrent.ExecutionException- if this strand has terminated as a result of an uncaught exception (which will be the- causeof the thrown- ExecutionException.
- java.util.concurrent.TimeoutException- if this strand did not terminate by the time the timeout has elapsed.
- java.lang.InterruptedException
 
 - 
joinNoSuspendpublic final Fiber<V> joinNoSuspend() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException - Throws:
- java.util.concurrent.ExecutionException
- java.lang.InterruptedException
 
 - 
joinNoSuspendpublic final Fiber<V> joinNoSuspend(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException - Throws:
- java.util.concurrent.ExecutionException
- java.lang.InterruptedException
- java.util.concurrent.TimeoutException
 
 - 
get@Suspendable public final V get() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException 
 - 
get@Suspendable public final V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException 
 - 
isDonepublic final boolean isDone() 
 - 
cancelpublic final boolean cancel(boolean mayInterruptIfRunning) - Specified by:
- cancelin interface- java.util.concurrent.Future<V>
 
 - 
isCancelledpublic final boolean isCancelled() - Specified by:
- isCancelledin interface- java.util.concurrent.Future<V>
 
 - 
setUncaughtExceptionHandlerpublic final void setUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh) Set the handler invoked when this fiber abruptly terminates due to an uncaught exception.A fiber can take full control of how it responds to uncaught exceptions by having its uncaught exception handler explicitly set. - Specified by:
- setUncaughtExceptionHandlerin class- Strand
- Parameters:
- eh- the object to use as this fiber's uncaught exception handler. If- nullthen this fiber has no explicit handler.
- See Also:
- setDefaultUncaughtExceptionHandler(co.paralleluniverse.strands.Strand.UncaughtExceptionHandler)
 
 - 
getUncaughtExceptionHandlerpublic final Strand.UncaughtExceptionHandler getUncaughtExceptionHandler() Returns the handler invoked when this fiber abruptly terminates due to an uncaught exception.- Specified by:
- getUncaughtExceptionHandlerin class- Strand
 
 - 
getDefaultUncaughtExceptionHandlerpublic static Strand.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() Returns the default handler invoked when a fiber abruptly terminates due to an uncaught exception. If the returned value isnull, there is no default.
 - 
setDefaultUncaughtExceptionHandlerpublic static void setDefaultUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh) Set the default handler invoked when a fiber abruptly terminates due to an uncaught exception, and no other handler has been defined for that fiber.- Parameters:
- eh- the object to use as the default uncaught exception handler. If- nullthen there is no default handler.
- See Also:
- setUncaughtExceptionHandler(co.paralleluniverse.strands.Strand.UncaughtExceptionHandler),- getUncaughtExceptionHandler()
 
 - 
getStackTracepublic final java.lang.StackTraceElement[] getStackTrace() Description copied from class:StrandReturns an array of stack trace elements representing the stack dump of this strand. This method will return a zero-length array if this strand has not started, has started but has not yet been scheduled to run by the system, or has terminated. If the returned array is of non-zero length then the first element of the array represents the top of the stack, which is the most recent method invocation in the sequence. The last element of the array represents the bottom of the stack, which is the least recent method invocation in the sequence.Some virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning this strand is permitted to return a zero-length array from this method. - Specified by:
- getStackTracein class- Strand
- Returns:
- an array of StackTraceElements, each represents one stack frame.
 
 - 
dumpStackpublic static void dumpStack() 
 - 
toStringpublic final java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
isRecordingLevelprotected final boolean isRecordingLevel(int level) 
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7)
 - 
recordprotected final void record(int level, java.lang.String clazz, java.lang.String method, java.lang.String format, java.lang.Object... args)
 - 
parkAndSerializepublic static void parkAndSerialize(FiberWriter writer) throws SuspendExecution Parks the fiber and allows the given callback to serialize it.- Parameters:
- writer- a callback that can serialize the fiber.
- Throws:
- SuspendExecution
 
 - 
parkAndCustomSerializepublic static void parkAndCustomSerialize(CustomFiberWriter writer) throws SuspendExecution Parks the fiber and allows the given callback to serialize it, optimized for use cases where the callback object has a custom way to obtain the required serializer (e.g. from a serializer pool)- Parameters:
- writer- a callback that can serialize the fiber.
- Throws:
- SuspendExecution
 
 - 
unparkSerializedpublic static <V> Fiber<V> unparkSerialized(byte[] serFiber, FiberScheduler scheduler) Deserializes a fiber from the given byte array and unparks it.- Parameters:
- serFiber- The byte array containing a fiber's serialized form.
- scheduler- The- FiberSchedulerto use for scheduling the fiber.
- Returns:
- The deserialized, running fiber.
 
 - 
unparkDeserializedpublic static <V> Fiber<V> unparkDeserialized(Fiber<V> f, FiberScheduler scheduler) Unparks a fiber that's been deserialized (with the help ofgetFiberSerializer()- Parameters:
- f- The deserialized fiber
- scheduler- The- FiberSchedulerto use for scheduling the fiber.
- Returns:
- The fiber
 
 - 
getFiberSerializerpublic static co.paralleluniverse.io.serialization.ByteArraySerializer getFiberSerializer() Returns aByteArraySerializercapable of serializing an object graph containing fibers.
 - 
getFiberSerializerpublic static co.paralleluniverse.io.serialization.ByteArraySerializer getFiberSerializer(boolean includeThreadLocals) Returns aByteArraySerializercapable of serializing an object graph containing fibers.- Parameters:
- includeThreadLocals- if true, thread/fiber local storage slots will also be serialised. You may want to set this to false if you are using frameworks that put things that cannot be properly serialised into TLS slots, or if the feature causes other issues.
 
 
- 
 
-