United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6402537 LockSupport.park with large timeout overflows, causing immediate return, resulting in busy-poll loop
JDK-6402537 : LockSupport.park with large timeout overflows, causing immediate return, resulting in busy-poll loop

Details
Type:
Bug
Submit Date:
2006-03-23
Status:
Closed
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2006-04-26
Component:
hotspot
OS:
solaris
Sub-Component:
runtime
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
If a very long timeout is passed to a blocking method (such as java.util.concurrent.LinkedBlockingQueue.poll) that ultimately uses LockSupport.park, the park call returns immediately instead of suspending the thread. Because park is allowed to return spuriously, the calling code always loops checking the condition it was waiting for and recalling park. This results in a busy-wait loop as the method constantly recalls park, which keeps returning immediately.

                                    

Comments
WORK AROUND

Use realistic timeout values. (The raw overflow only occurs for timeouts > 31.8 years)
                                     
2006-03-23
SUGGESTED FIX

Check for overflow and limit the time to the maximum supported.
                                     
2006-03-23
EVALUATION

On Solaris and Linux the low-level park code transforms a timeout into an absolute time for use with the platform specific timed-wait mechanism. Some platform mechanisms have limits to the lengths of time they can wait, partly due to the use of 32-bit signed values. If the requested timeout results in an overflow then the resulting time is in the past and the platform mechanism returns immediately reporting the ETIME status.

If a higher-level operation, like a Condition.await, sees the immediate return but finds neither the condition is satisfied nor the timeout elapsed, then it will re-park. The re-park again returns immediately and we get a busy-poll loop.
                                     
2006-03-23



Hardware and Software, Engineered to Work Together