Jtest logo




Contents  Previous  Next  Index

TRS.ANF


Do not use 'notify()'; use 'notifyAll()' instead

Description

This rule flags any occurrence of `notify()'.

Multiple threads may be waiting on the same object. Using 'notify()' picks one of the waiting threads and wakes it up. Because there is no way to predict which thread will be awakened, you should use `notifyAll()' to wake up waiting threads.

Example

 package TRS;
 public class ANF {
     public synchronized void notifyThread() {
         notify();
     }
 }

Repair

Replace 'notify()' with 'notifyAll()'

Reference

Arnold, Ken, and Gosling, James The Java Programming Language. 2d ed. Addison Wesley, 1997, pp.188-190.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft