Top Description Inners Fields Constructors Methods
jdk.internal.misc

public Class ThreadTracker

extends Object
Class Inheritance
Imports
java.util.Set, java.util.concurrent.ConcurrentHashMap

Tracks threads to help detect reentrancy without using ThreadLocal variables. A thread invokes the begin or tryBegin methods at the start of a block, and the end method at the end of a block.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
ThreadTracker.ThreadRef

A reference to a Thread that is suitable for use as a key in a collection.

Field Summary

Modifier and TypeField and Description
private final Set<ThreadTracker.ThreadRef>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
begin()

Adds the current thread to thread set if not already in the set.

public boolean
contains(Thread thread)

Returns true if the given thread is tracked.

public void
end(Object key)

Removes the thread identified by the key from the thread set.

public Object
tryBegin()

Adds the current thread to thread set if not already in the set.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

threadsback to summary
private final Set<ThreadTracker.ThreadRef> threads

Constructor Detail

ThreadTrackerback to summary
public ThreadTracker()

Method Detail

beginback to summary
public Object begin()

Adds the current thread to thread set if not already in the set. Returns a key to remove the thread.

containsback to summary
public boolean contains(Thread thread)

Returns true if the given thread is tracked.

endback to summary
public void end(Object key)

Removes the thread identified by the key from the thread set.

tryBeginback to summary
public Object tryBegin()

Adds the current thread to thread set if not already in the set. Returns a key to remove the thread or null if already in the set.

jdk.internal.misc back to summary

private final Record ThreadTracker.ThreadRef

extends Record
Class Inheritance
Record Components
thread:Thread

A reference to a Thread that is suitable for use as a key in a collection. The hashCode/equals methods do not invoke the Thread hashCode/equals method as they may run arbitrary code and/or leak references to Thread objects.

Field Summary

Modifier and TypeField and Description
private final Thread
thread

Record Component accessed by thread().

Constructor Summary

AccessConstructor and Description
private
ThreadRef(Thread thread)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Thread
thread()

Record Component getter of thread.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

threadback to summary
private final Thread thread

Record Component accessed by thread().

Constructor Detail

ThreadRefback to summary
private ThreadRef(Thread thread)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

Annotations
@Override
threadback to summary
public Thread thread()

Record Component getter of thread.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.