< prev index next >

src/jdk.management/share/classes/com/sun/management/ThreadMXBean.java

Print this page

132      *         measurement.
133      *
134      * @see #isThreadAllocatedMemorySupported
135      * @see #isThreadAllocatedMemoryEnabled
136      * @see #setThreadAllocatedMemoryEnabled
137      *
138      * @since 14
139      */
140     public default long getCurrentThreadAllocatedBytes() {
141         return getThreadAllocatedBytes(Thread.currentThread().getId());
142     }
143 
144     /**
145      * Returns an approximation of the total amount of memory, in bytes,
146      * allocated in heap memory for the thread with the specified ID.
147      * The returned value is an approximation because some Java virtual machine
148      * implementations may use object allocation mechanisms that result in a
149      * delay between the time an object is allocated and the time its size is
150      * recorded.
151      * <p>
152      * If the thread with the specified ID is not alive or does not exist,
153      * this method returns {@code -1}. If thread memory allocation measurement
154      * is disabled, this method returns {@code -1}.
155      * A thread is alive if it has been started and has not yet died.
156      * <p>
157      * If thread memory allocation measurement is enabled after the thread has
158      * started, the Java virtual machine implementation may choose any time up
159      * to and including the time that the capability is enabled as the point
160      * where thread memory allocation measurement starts.
161      *
162      * @param id the thread ID of a thread
163      * @return an approximation of the total memory allocated, in bytes, in
164      * heap memory for the thread with the specified ID
165      * if the thread with the specified ID exists, the thread is alive,
166      * and thread memory allocation measurement is enabled;
167      * {@code -1} otherwise.
168      *
169      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
170      * @throws UnsupportedOperationException if the Java virtual
171      *         machine implementation does not support thread memory allocation
172      *         measurement.
173      *
174      * @see #isThreadAllocatedMemorySupported
175      * @see #isThreadAllocatedMemoryEnabled

132      *         measurement.
133      *
134      * @see #isThreadAllocatedMemorySupported
135      * @see #isThreadAllocatedMemoryEnabled
136      * @see #setThreadAllocatedMemoryEnabled
137      *
138      * @since 14
139      */
140     public default long getCurrentThreadAllocatedBytes() {
141         return getThreadAllocatedBytes(Thread.currentThread().getId());
142     }
143 
144     /**
145      * Returns an approximation of the total amount of memory, in bytes,
146      * allocated in heap memory for the thread with the specified ID.
147      * The returned value is an approximation because some Java virtual machine
148      * implementations may use object allocation mechanisms that result in a
149      * delay between the time an object is allocated and the time its size is
150      * recorded.
151      * <p>
152      * If the thread with the specified ID is a virtual thread, is not alive,
153      * or does not exist, this method returns {@code -1}. If thread memory
154      * allocation measurement is disabled, this method returns {@code -1}.
155      * A thread is alive if it has been started and has not yet terminated.
156      * <p>
157      * If thread memory allocation measurement is enabled after the thread has
158      * started, the Java virtual machine implementation may choose any time up
159      * to and including the time that the capability is enabled as the point
160      * where thread memory allocation measurement starts.
161      *
162      * @param id the thread ID of a thread
163      * @return an approximation of the total memory allocated, in bytes, in
164      * heap memory for the thread with the specified ID
165      * if the thread with the specified ID exists, the thread is alive,
166      * and thread memory allocation measurement is enabled;
167      * {@code -1} otherwise.
168      *
169      * @throws IllegalArgumentException if {@code id} {@code <=} {@code 0}.
170      * @throws UnsupportedOperationException if the Java virtual
171      *         machine implementation does not support thread memory allocation
172      *         measurement.
173      *
174      * @see #isThreadAllocatedMemorySupported
175      * @see #isThreadAllocatedMemoryEnabled
< prev index next >