Class StackWalker
java.lang.Object
java.lang.StackWalker
This provides a facility for iterating over the call stack of the current
thread. A StackWalker object may be used multiple times by different threads,
but it will represent the state of the current thread at the time the stack
is walked. A StackWalker may be provided with one or more Option settings to
include information and stack frames such as reflection methods, hidden
frames, and Class objects.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSelects what type of stack and method information is provided by the StackWalker.static interfaceContains information about the StackWalker's current stack frame. -
Method Summary
Modifier and TypeMethodDescriptionvoidforEach(Consumer<? super StackWalker.StackFrame> action) Class<?> Get the caller of the caller of this function, eliding any reflection or hidden frames.static StackWalkerFactory method to create a StackWalker instance with no options set.static StackWalkergetInstance(StackWalker.Option option) Factory method to create a StackWalker with one option.static StackWalkergetInstance(Set<StackWalker.Option> options) Factory method to create a StackWalker with any number of options.static StackWalkergetInstance(Set<StackWalker.Option> options, int estimatedDepth) Factory method to create a StackWalker.<T> Twalk(Function<? super Stream<StackWalker.StackFrame>, ? extends T> function) Traverse the calling thread's stack at the time this method is called and applyfunctionto each stack frame.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
getInstance
Factory method to create a StackWalker instance with no options set.- Returns:
- StackWalker StackWalker object
-
getInstance
Factory method to create a StackWalker with one option. This is provided for the case where only a single option is required.- Parameters:
option- select the type of information to include- Returns:
- StackWalker instance configured with the value of option
-
getInstance
Factory method to create a StackWalker with any number of options.- Parameters:
options- select the types of information to include- Returns:
- StackWalker instance configured with the given options
-
getInstance
Factory method to create a StackWalker.- Parameters:
options- select the types of information to includeestimatedDepth- hint for the size of buffer to use. Must be 1 or greater- Returns:
- StackWalker instance with the given options specifying the stack frame information it can access
-
forEach
- Parameters:
action-Consumerobject Iterate over the stack from top to bottom and apply theConsumerto eachStackWalker.StackFrame
-
getCallerClass
Get the caller of the caller of this function, eliding any reflection or hidden frames.- Returns:
- Class object for the method calling the current method.
- Throws:
UnsupportedOperationException- if the StackWalker was not created withStackWalker.Option.RETAIN_CLASS_REFERENCEIllegalStateException- if the caller is at the bottom of the stack
-
walk
Traverse the calling thread's stack at the time this method is called and applyfunctionto each stack frame.- Type Parameters:
T- the type of the return value from applying function to the stream- Parameters:
function- operation to apply to the stream- Returns:
- the value returned by
function
-