Class Strand
- java.lang.Object
-
- co.paralleluniverse.strands.Strand
-
- Direct Known Subclasses:
Fiber
public abstract class Strand extends java.lang.Object
A Strand is either a Thread or a Fiber
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Strand.State
A strand's running statestatic interface
Strand.UncaughtExceptionHandler
Interface for handlers invoked when aStrand
abruptly terminates due to an uncaught exception.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<Strand>
currentStrand
static int
MAX_PRIORITY
The maximum priority that a strand can have.static int
MIN_PRIORITY
The minimum priority that a strand can have.static int
NORM_PRIORITY
The default priority that is assigned to a strand.
-
Constructor Summary
Constructors Constructor Description Strand()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Strand
clone(Strand strand, SuspendableCallable<?> target)
static Strand
clone(Strand strand, SuspendableRunnable target)
static Strand
currentStrand()
Returns the current strand.static void
dumpStack()
Prints a stack trace of the current strand to the standard error stream.static boolean
equals(java.lang.Object strand1, java.lang.Object strand2)
Tests whether two strands represent the same fiber or thread.abstract java.lang.Object
get()
abstract java.lang.Object
get(long timeout, java.util.concurrent.TimeUnit unit)
abstract java.lang.Object
getBlocker()
Returns the blocker object supplied to the most recent invocation of apark
method that has not yet unblocked, or null if not blocked.abstract long
getId()
Returns the strand's id.abstract java.lang.InterruptedException
getInterruptStack()
Returns anInterruptedException
that was created when theinterrupt()
method was called, and can be used to retrieve the stack trace of the strand that interrupted this strand.abstract java.lang.String
getName()
Returns the strand's name.abstract int
getPriority()
Returns this strand's priority.abstract java.lang.StackTraceElement[]
getStackTrace()
Returns an array of stack trace elements representing the stack dump of this strand.abstract Strand.State
getState()
Returns the strand's current running state.abstract Strand.UncaughtExceptionHandler
getUncaughtExceptionHandler()
Returns the handler invoked when this strand abruptly terminates due to an uncaught exception.abstract java.lang.Object
getUnderlying()
Returns the underlying object of this strand, namely aThread
or aFiber
.abstract void
interrupt()
Interrupts this strand.static boolean
interrupted()
Tests whether the current strand has been interrupted.abstract boolean
isAlive()
Tests whether this strand is alive, namely it has been started but not yet terminated.static boolean
isCurrentFiber()
Tests whether this function is called within a fiber.boolean
isDone()
abstract boolean
isFiber()
Tests whether this strand is a fiber.abstract boolean
isInterrupted()
Tests whether this strand has been interrupted.abstract boolean
isTerminated()
Tests whether this strand has terminated.abstract void
join()
Awaits the termination of this strand.abstract void
join(long timeout, java.util.concurrent.TimeUnit unit)
Awaits the termination of this strand, at most for the timeout duration specified.static void
join(java.lang.Object strand)
Awaits the termination of a given strand.static void
join(java.lang.Object strand, long timeout, java.util.concurrent.TimeUnit unit)
Awaits the termination of a given strand, at most for the timeout duration specified.static Strand
of(Fiber fiber)
Returns a strand representing the given fiber.static Strand
of(java.lang.Object owner)
static Strand
of(java.lang.Thread thread)
Returns a strand representing the given thread.static void
park()
Disables the current strand for scheduling purposes unless the permit is available.static void
park(java.lang.Object blocker)
Disables the current strand for scheduling purposes unless the permit is available.static void
parkAndUnpark(Strand other)
static void
parkAndUnpark(Strand other, java.lang.Object blocker)
static void
parkNanos(long nanos)
Disables the current strand for thread scheduling purposes, for up to the specified waiting time, unless the permit is available.static void
parkNanos(java.lang.Object blocker, long nanos)
Disables the current strand for thread scheduling purposes, for up to the specified waiting time, unless the permit is available.static void
parkUntil(java.lang.Object blocker, long deadline)
Disables the current strand for scheduling purposes, until the specified deadline, unless the permit is available.static void
printStackTrace(java.lang.StackTraceElement[] trace, java.io.PrintStream out)
This utility method prints a stack-trace into aPrintStream
static void
printStackTrace(java.lang.StackTraceElement[] trace, java.io.PrintWriter out)
This utility method prints a stack-trace into aPrintWriter
abstract Strand
setName(java.lang.String name)
Sets this strand's name.abstract Strand
setPriority(int newPriority)
Attempts to change the priority of this strand.abstract void
setUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh)
Set the handler invoked when this strand abruptly terminates due to an uncaught exception.static void
sleep(long millis)
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.static void
sleep(long millis, int nanos)
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.static void
sleep(long duration, java.util.concurrent.TimeUnit unit)
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.abstract Strand
start()
Starts the strand.static java.lang.Runnable
toRunnable(SuspendableCallable<?> callable)
A utility method that converts aSuspendableCallable
to aRunnable
so that it could run as the target of a thread.static java.lang.Runnable
toRunnable(SuspendableRunnable runnable)
A utility method that converts aSuspendableRunnable
to aRunnable
so that it could run as the target of a thread.static java.lang.String
toString(java.lang.StackTraceElement[] trace)
This utility method turns a stack-trace into a human readable, multi-line string.abstract void
unpark()
Makes available the permit for this strand, if it was not already available.static void
unpark(Strand strand)
Makes available the permit for the given strand, if it was not already available.static void
unpark(Strand strand, java.lang.Object unblocker)
Makes available the permit for the given strand, if it was not already available.abstract void
unpark(java.lang.Object unblocker)
Makes available the permit for this strand, if it was not already available.static void
unpark(java.lang.Thread strand)
Makes available the permit for the given strand, if it was not already available.static java.lang.Object
unwrapSuspendable(java.lang.Runnable r)
Returns theSuspendableCallable
orSuspendableRunnable
, wrapped by the givenRunnable
bytoRunnable
.static void
yield()
A hint to the scheduler that the current strand is willing to yield its current use of a processor.static void
yieldAndUnpark(Strand other)
static void
yieldAndUnpark(Strand other, java.lang.Object blocker)
-
-
-
Field Detail
-
MIN_PRIORITY
public static final int MIN_PRIORITY
The minimum priority that a strand can have.- See Also:
- Constant Field Values
-
NORM_PRIORITY
public static final int NORM_PRIORITY
The default priority that is assigned to a strand.- See Also:
- Constant Field Values
-
MAX_PRIORITY
public static final int MAX_PRIORITY
The maximum priority that a strand can have.- See Also:
- Constant Field Values
-
currentStrand
protected static java.lang.ThreadLocal<Strand> currentStrand
-
-
Method Detail
-
of
public static Strand of(java.lang.Object owner)
-
of
public static Strand of(java.lang.Thread thread)
Returns a strand representing the given thread.
-
of
public static Strand of(Fiber fiber)
Returns a strand representing the given fiber. The current implementation simply returns the fiber itself asFiber
extendsFiber
.
-
isFiber
public abstract boolean isFiber()
Tests whether this strand is a fiber.- Returns:
true
iff this strand is a fiber.
-
getUnderlying
public abstract java.lang.Object getUnderlying()
Returns the underlying object of this strand, namely aThread
or aFiber
.
-
getName
public abstract java.lang.String getName()
Returns the strand's name.- Returns:
- The strand's name. May be
null
.
-
setName
public abstract Strand setName(java.lang.String name)
Sets this strand's name. This method may only be called before the strand is started.- Parameters:
name
- the new name- Returns:
this
-
setPriority
public abstract Strand setPriority(int newPriority)
Attempts to change the priority of this strand. The priority of this thread is set to the smaller of the specifiednewPriority
and the maximum permitted priority of the strand's thread group, if the strand is a thread. The strand priority's semantics - or even if it is ignored completely - is entirely up to the strand's scheduler, be it the OS kernel in the case of a thread, or the fiber scheduler, in the case of a fiber.- Parameters:
newPriority
- priority to set this strand to- Throws:
java.lang.IllegalArgumentException
- If the priority is not in the rangeMIN_PRIORITY
toMAX_PRIORITY
- See Also:
getPriority()
,MAX_PRIORITY
,MIN_PRIORITY
-
getPriority
public abstract int getPriority()
Returns this strand's priority.- Returns:
- this strand's priority.
- See Also:
setPriority(int)
-
isAlive
public abstract boolean isAlive()
Tests whether this strand is alive, namely it has been started but not yet terminated.
-
isTerminated
public abstract boolean isTerminated()
Tests whether this strand has terminated.
-
start
public abstract Strand start()
Starts the strand.- Returns:
this
- Throws:
java.lang.IllegalThreadStateException
- if the strand has already been started
-
join
public abstract void join() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Awaits the termination of this strand. This method blocks until this strand terminates.- Throws:
java.util.concurrent.ExecutionException
- if this strand has terminated as a result of an uncaught exception (which will be thecause
of the thrownExecutionException
.java.lang.InterruptedException
-
join
public abstract void join(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Awaits the termination of this strand, at most for the timeout duration specified. This method blocks until this strand terminates or the timeout elapses.- Parameters:
timeout
- the maximum duration to wait for the strand to terminate in the time unit specified byunit
.unit
- the time unit oftimeout
.- Throws:
java.util.concurrent.TimeoutException
- if this strand did not terminate by the time the timeout has elapsed.java.util.concurrent.ExecutionException
- if this strand has terminated as a result of an uncaught exception (which will be thecause
of the thrownExecutionException
.java.lang.InterruptedException
-
get
public abstract java.lang.Object get() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
- Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException
-
get
public abstract java.lang.Object get(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
-
isDone
public boolean isDone()
-
interrupt
public abstract void interrupt()
Interrupts this strand. If this strand is blocked, the blocking function will throw anInterruptedException
. Otherwise, the strand may test its interrupted status with theinterrupted()
orisInterrupted()
method.
-
isInterrupted
public abstract boolean isInterrupted()
Tests whether this strand has been interrupted.- Returns:
true
if the strand has been interrupted;false
otherwise.- See Also:
interrupt()
,interrupted()
-
getInterruptStack
public abstract java.lang.InterruptedException getInterruptStack()
Returns anInterruptedException
that was created when theinterrupt()
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 returnnull
if this information is not available. The current implementation always returnsnull
if this strand is a thread.
-
unpark
public abstract void unpark()
-
unpark
public abstract void unpark(java.lang.Object unblocker)
Makes available the permit for this strand, if it was not already available. If this strand was blocked onpark()
then it will unblock. Otherwise, its next call topark()
is guaranteed not to block. This operation is not guaranteed to have any effect at all if the given strand has not been started.- Parameters:
unblocker
- the synchronization object responsible for this strand unparking
-
getBlocker
public abstract java.lang.Object getBlocker()
Returns the blocker object supplied to the most recent invocation of apark
method 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.- Returns:
- the blocker
-
getState
public abstract Strand.State getState()
Returns the strand's current running state.
-
getStackTrace
public abstract java.lang.StackTraceElement[] getStackTrace()
Returns 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.
- Returns:
- an array of
StackTraceElement
s, each represents one stack frame.
-
getId
public abstract long getId()
Returns the strand's id. Id's are unique within a single JVM instance.
-
currentStrand
public static Strand currentStrand()
Returns the current strand. This method will return a strand representing the fiber calling this method, or the current thread if this method is not called within a fiber.- Returns:
- A strand representing the current fiber or thread
-
isCurrentFiber
public static boolean isCurrentFiber()
Tests whether this function is called within a fiber. This method might be faster thanFiber.currentFiber() != null
.- Returns:
true
iff the code that called this method is executing in a fiber.
-
interrupted
public static boolean interrupted()
Tests whether the current strand has been interrupted. The interrupted status of the strand is cleared by this method. In other words, if this method were to be called twice in succession, the second call would returnfalse
(unless the current strand were interrupted again, after the first call had cleared its interrupted status and before the second call had examined it).- Returns:
true
if the current thread has been interrupted;false
otherwise.- See Also:
interrupt()
,isInterrupted()
-
join
public static void join(java.lang.Object strand) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Awaits the termination of a given strand. This method blocks until this strand terminates.- Parameters:
strand
- the strand to join. May be an object of typeStrand
,Fiber
orThread
.- Throws:
java.util.concurrent.ExecutionException
- if this strand has terminated as a result of an uncaught exception (which will be thecause
of the thrownExecutionException
.java.lang.InterruptedException
-
join
public static void join(java.lang.Object strand, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Awaits the termination of a given strand, at most for the timeout duration specified. This method blocks until this strand terminates or the timeout elapses.- Parameters:
strand
- the strand to join. May be an object of typeStrand
,Fiber
orThread
.timeout
- the maximum duration to wait for the strand to terminate in the time unit specified byunit
.unit
- the time unit oftimeout
.- Throws:
java.util.concurrent.TimeoutException
- if this strand did not terminate by the time the timeout has elapsed.java.util.concurrent.ExecutionException
- if this strand has terminated as a result of an uncaught exception (which will be thecause
of the thrownExecutionException
.java.lang.InterruptedException
-
yield
public static void yield() throws SuspendExecution
A hint to the scheduler that the current strand is willing to yield its current use of a processor. The scheduler is free to ignore this hint.Yield is a heuristic attempt to improve relative progression between strands that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.
- Throws:
SuspendExecution
-
sleep
public static void sleep(long millis) throws SuspendExecution, java.lang.InterruptedException
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.- Parameters:
millis
- the length of time to sleep in milliseconds- Throws:
java.lang.IllegalArgumentException
- if the value ofmillis
is negativejava.lang.InterruptedException
- if any strand has interrupted the current strand. The interrupted status of the current strand is cleared when this exception is thrown.SuspendExecution
-
sleep
public static void sleep(long millis, int nanos) throws SuspendExecution, java.lang.InterruptedException
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.- Parameters:
millis
- the length of time to sleep in millisecondsnanos
-0-999999
additional nanoseconds to sleep- Throws:
java.lang.IllegalArgumentException
- if the value ofmillis
is negative, or the value ofnanos
is not in the range0-999999
java.lang.InterruptedException
- if any strand has interrupted the current strand. The interrupted status of the current strand is cleared when this exception is thrown.SuspendExecution
-
sleep
public static void sleep(long duration, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
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.- Parameters:
duration
- the length of time to sleep in the time unit specified byunit
.unit
- the time unit ofduration
.- Throws:
java.lang.InterruptedException
- if any strand has interrupted the current strand. The interrupted status of the current strand is cleared when this exception is thrown.SuspendExecution
-
park
public static void park() throws SuspendExecution
Disables the current strand for scheduling purposes unless the permit is available.If the permit is available then it is consumed and the call returns immediately; otherwise the current strand becomes disabled for scheduling purposes and lies dormant until one of three things happens:
- Some other strand invokes
unpark
with the current strand as the target; or - Some other strand
interrupts
the current strand; or - The call spuriously (that is, for no reason) returns.
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the strand to park in the first place. Callers may also determine, for example, the interrupt status of the strand upon return.
- Throws:
SuspendExecution
- Some other strand invokes
-
park
public static void park(java.lang.Object blocker) throws SuspendExecution
Disables the current strand for scheduling purposes unless the permit is available.If the permit is available then it is consumed and the call returns immediately; otherwise the current strand becomes disabled for scheduling purposes and lies dormant until one of three things happens:
- Some other strand invokes
unpark
with the current strand as the target; or - Some other strand
interrupts
the current strand; or - The call spuriously (that is, for no reason) returns.
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the strand to park in the first place. Callers may also determine, for example, the interrupt status of the strand upon return.
- Parameters:
blocker
- the synchronization object responsible for this strand parking- Throws:
SuspendExecution
- Some other strand invokes
-
parkAndUnpark
public static void parkAndUnpark(Strand other, java.lang.Object blocker) throws SuspendExecution
- Throws:
SuspendExecution
-
parkAndUnpark
public static void parkAndUnpark(Strand other) throws SuspendExecution
- Throws:
SuspendExecution
-
yieldAndUnpark
public static void yieldAndUnpark(Strand other, java.lang.Object blocker) throws SuspendExecution
- Throws:
SuspendExecution
-
yieldAndUnpark
public static void yieldAndUnpark(Strand other) throws SuspendExecution
- Throws:
SuspendExecution
-
parkNanos
public static void parkNanos(long nanos) throws SuspendExecution
Disables the current strand for thread scheduling purposes, for up to the specified waiting time, unless the permit is available.If the permit is available then it is consumed and the call returns immediately; otherwise the current strand becomes disabled for scheduling purposes and lies dormant until one of four things happens:
- Some other strand invokes
unpark
with the current strand as the target; or - Some other strand
interrupts
the current strand; or - The specified waiting time elapses; or
- The call spuriously (that is, for no reason) returns.
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the strand to park in the first place. Callers may also determine, for example, the interrupt status of the strand, or the elapsed time upon return.
- Parameters:
nanos
- the maximum number of nanoseconds to wait- Throws:
SuspendExecution
- Some other strand invokes
-
parkNanos
public static void parkNanos(java.lang.Object blocker, long nanos) throws SuspendExecution
Disables the current strand for thread scheduling purposes, for up to the specified waiting time, unless the permit is available.If the permit is available then it is consumed and the call returns immediately; otherwise the current strand becomes disabled for scheduling purposes and lies dormant until one of four things happens:
- Some other strand invokes
unpark
with the current strand as the target; or - Some other strand
interrupts
the current strand; or - The specified waiting time elapses; or
- The call spuriously (that is, for no reason) returns.
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the strand to park in the first place. Callers may also determine, for example, the interrupt status of the strand, or the elapsed time upon return.
- Parameters:
blocker
- the synchronization object responsible for this strand parkingnanos
- the maximum number of nanoseconds to wait- Throws:
SuspendExecution
- Some other strand invokes
-
parkUntil
public static void parkUntil(java.lang.Object blocker, long deadline) throws SuspendExecution
Disables the current strand for scheduling purposes, until the specified deadline, unless the permit is available.If the permit is available then it is consumed and the call returns immediately; otherwise the current strand becomes disabled for scheduling purposes and lies dormant until one of four things happens:
- Some other strand invokes
unpark
with the current strand as the target; or - Some other strand
interrupts
the current strand; or - The specified deadline passes; or
- The call spuriously (that is, for no reason) returns.
This method does not report which of these caused the method to return. Callers should re-check the conditions which caused the strand to park in the first place. Callers may also determine, for example, the interrupt status of the strand, or the current time upon return.
- Parameters:
blocker
- the synchronization object responsible for this strand parkingdeadline
- the absolute time, in milliseconds from the Epoch, to wait until- Throws:
SuspendExecution
- Some other strand invokes
-
unpark
public static void unpark(Strand strand)
Makes available the permit for the given strand, if it was not already available. If the strand was blocked onpark
then it will unblock. Otherwise, its next call topark
is guaranteed not to block. This operation is not guaranteed to have any effect at all if the given strand has not been started.- Parameters:
strand
- the strand to unpark, ornull
, in which case this operation has no effect
-
unpark
public static void unpark(Strand strand, java.lang.Object unblocker)
Makes available the permit for the given strand, if it was not already available. If the strand was blocked onpark
then it will unblock. Otherwise, its next call topark
is guaranteed not to block. This operation is not guaranteed to have any effect at all if the given strand has not been started.- Parameters:
strand
- the strand to unpark, ornull
, in which case this operation has no effectunblocker
- the synchronization object responsible for the strand unparking
-
unpark
public static void unpark(java.lang.Thread strand)
Makes available the permit for the given strand, if it was not already available. If the strand was blocked onpark
then it will unblock. Otherwise, its next call topark
is guaranteed not to block. This operation is not guaranteed to have any effect at all if the given strand has not been started.- Parameters:
strand
- the strand to unpark, ornull
, in which case this operation has no effect
-
dumpStack
public static void dumpStack()
Prints a stack trace of the current strand to the standard error stream. This method is used only for debugging.
-
setUncaughtExceptionHandler
public abstract void setUncaughtExceptionHandler(Strand.UncaughtExceptionHandler eh)
Set the handler invoked when this strand abruptly terminates due to an uncaught exception.A strand can take full control of how it responds to uncaught exceptions by having its uncaught exception handler explicitly set.
- Parameters:
eh
- the object to use as this strand's uncaught exception handler. Ifnull
then this strand has no explicit handler.
-
getUncaughtExceptionHandler
public abstract Strand.UncaughtExceptionHandler getUncaughtExceptionHandler()
Returns the handler invoked when this strand abruptly terminates due to an uncaught exception.
-
equals
public static boolean equals(java.lang.Object strand1, java.lang.Object strand2)
Tests whether two strands represent the same fiber or thread.- Parameters:
strand1
- May be an object of typeStrand
,Fiber
orThread
.strand2
- May be an object of typeStrand
,Fiber
orThread
.- Returns:
true
if the two strands represent the same fiber or the same thread;false
otherwise.
-
clone
public static Strand clone(Strand strand, SuspendableCallable<?> target)
-
clone
public static Strand clone(Strand strand, SuspendableRunnable target)
-
toRunnable
public static java.lang.Runnable toRunnable(SuspendableRunnable runnable)
A utility method that converts aSuspendableRunnable
to aRunnable
so that it could run as the target of a thread.
-
toRunnable
public static java.lang.Runnable toRunnable(SuspendableCallable<?> callable)
A utility method that converts aSuspendableCallable
to aRunnable
so that it could run as the target of a thread. The return value of the callable is ignored.
-
unwrapSuspendable
public static java.lang.Object unwrapSuspendable(java.lang.Runnable r)
Returns theSuspendableCallable
orSuspendableRunnable
, wrapped by the givenRunnable
bytoRunnable
.
-
toString
public static java.lang.String toString(java.lang.StackTraceElement[] trace)
This utility method turns a stack-trace into a human readable, multi-line string.- Parameters:
trace
- a stack trace (such as returned fromgetStackTrace()
.- Returns:
- a nice (multi-line) string representation of the stack trace.
-
printStackTrace
public static void printStackTrace(java.lang.StackTraceElement[] trace, java.io.PrintStream out)
This utility method prints a stack-trace into aPrintStream
- Parameters:
trace
- a stack trace (such as returned fromgetStackTrace()
.out
- thePrintStream
into which the stack trace will be printed.
-
printStackTrace
public static void printStackTrace(java.lang.StackTraceElement[] trace, java.io.PrintWriter out)
This utility method prints a stack-trace into aPrintWriter
- Parameters:
trace
- a stack trace (such as returned fromgetStackTrace()
.out
- thePrintWriter
into which the stack trace will be printed.
-
-