JDK-6659215 : javax.management.timer.Timer frequently fails to start
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 1.2.1
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2008-02-05
  • Updated: 2011-05-25
  • Resolved: 2008-03-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10 b13Fixed 7Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 Professional
Version	5.0.2195 Service Pack 4 Build 2195

EXTRA RELEVANT SYSTEM CONFIGURATION :
Dual AMD 64 bit cpu

A DESCRIPTION OF THE PROBLEM :
If at least one past Notification falls due when the Timer is started, there is about   a 50% chance that it will fail . If 3 Notifacations fall due, then it may fail three times consecutively in a (programatic) loop. Once it has failed it doesn't function properly thereafter, until the program is restarted.
It can take several restarts to get it to run first time, after which it functions just fine.
Note that the error data below was obtained while running the program under Netbeans. The printStackTrace() is normally replaced by a simple message display indirectly using JOptionPane.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the Timer to start without error.
ACTUAL -
The error below was generated.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.util.ConcurrentModificationException
        at java.util.Hashtable$Enumerator.next(Hashtable.java:1031)
        at javax.management.timer.Timer.sendPastNotifications(Timer.java:1028)
        at javax.management.timer.Timer.start(Timer.java:318)
        at alarm.Alarm.<init>(Alarm.java:112)
        at alarm.Alarm$5.run(Alarm.java:448)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
If you can't pinpoint the problem with the data provided, then I can be reached at
###@###.###, and I'm prepared to send you the whole program.
I don't intend to spend days creating a test case.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found.

Comments
SUGGESTED FIX We will fix this bug by copying the values of the Timer table into an ArrayList, so modifying the table will not impact to the ArrayList.
27-02-2008

SUGGESTED FIX The problem is in Timer.sendPastNotifications, where a loop over timerTable.values() can change the Collection returned by that method, thus provoking a ConcurrentModificationException. The simplest fix is to split this loop into two loops. The first one builds a List<Object[]> containing the timerTable values that are in the past. The second one calls sendNotification (if currentFlag) and updateTimerTable (always) for each entry in the List.
21-02-2008

EVALUATION ###@###.### writes: The method "start" calls HashTable.values() to get a Collection of all posted notifications, and removes a posted notif from the Hashtable after sending it out. While working with this Collection we should not modify the Hashtable, otherwise a java.util.ConcurrentModificationException will be thrown.
05-02-2008