339 |
339 |
340 sleep(millis); |
340 sleep(millis); |
341 } |
341 } |
342 |
342 |
343 /** |
343 /** |
|
344 * Indicates that the caller is momentarily unable to progress, until the |
|
345 * occurrence of one or more actions on the part of other activities. By |
|
346 * invoking this method within each iteration of a spin-wait loop construct, |
|
347 * the calling thread indicates to the runtime that it is busy-waiting. |
|
348 * The runtime may take action to improve the performance of invoking |
|
349 * spin-wait loop constructions. |
|
350 * <p> |
|
351 * @apiNote |
|
352 * As an example consider a method in a class that spins in a loop until |
|
353 * some flag is set outside of that method. A call to the {@code onSpinWait} |
|
354 * method should be placed inside the spin loop. |
|
355 * <pre>{@code |
|
356 * class EventHandler { |
|
357 * volatile boolean eventNotificationNotReceived; |
|
358 * void waitForEventAndHandleIt() { |
|
359 * while ( eventNotificationNotReceived ) { |
|
360 * java.lang.Thread.onSpinWait(); |
|
361 * } |
|
362 * readAndProcessEvent(); |
|
363 * } |
|
364 * |
|
365 * void readAndProcessEvent() { |
|
366 * // Read event from some source and process it |
|
367 * . . . |
|
368 * } |
|
369 * } |
|
370 * }</pre> |
|
371 * <p> |
|
372 * The code above would remain correct even if the {@code onSpinWait} |
|
373 * method was not called at all. However on some architectures the Java |
|
374 * Virtual Machine may issue the processor instructions to address such |
|
375 * code patterns in a more beneficial way. |
|
376 * <p> |
|
377 * @since 9 |
|
378 */ |
|
379 @HotSpotIntrinsicCandidate |
|
380 public static void onSpinWait() {} |
|
381 |
|
382 /** |
344 * Initializes a Thread with the current AccessControlContext. |
383 * Initializes a Thread with the current AccessControlContext. |
345 * @see #init(ThreadGroup,Runnable,String,long,AccessControlContext,boolean) |
384 * @see #init(ThreadGroup,Runnable,String,long,AccessControlContext,boolean) |
346 */ |
385 */ |
347 private void init(ThreadGroup g, Runnable target, String name, |
386 private void init(ThreadGroup g, Runnable target, String name, |
348 long stackSize) { |
387 long stackSize) { |