cushon / issues-import

0 stars 0 forks source link

wait() should always be called inside a loop #166

Closed cushon closed 9 years ago

cushon commented 9 years ago

Original issue created by eaftan@google.com on 2013-07-31 at 07:16 PM


wait() should always be called inside a loop, to handle spurious wakeups. Consider a check to enforce this.

See http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#wait(long) for more details.

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2013-08-07 at 12:11 AM


(No comment entered for this change.)


Status: Started

cushon commented 9 years ago

Original comment posted by brianfromoregon on 2013-09-12 at 12:34 AM


Hi, fyi. We run crit path prod code where wait is called in a loop but that loop isn't in the same method as the wait call. We want a spurious wakeup to pop the call stack as if the thread were notify'd.

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2013-09-12 at 05:29 PM


I've noticed this pattern in some of our code as well. I was thinking of providing an annotation to document that the loop is outside the method. Then this checker would not issue an error if the enclosing method has that annotation, and we could also check that any method with the annotation really is called in a loop.

cushon commented 9 years ago

Original comment posted by supertri@google.com on 2013-11-20 at 01:36 AM


Check has been committed to the repository, although the suggested fix could be improved.


Status: Fixed