United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6659215 javax.management.timer.Timer frequently fails to start
JDK-6659215 : javax.management.timer.Timer frequently fails to start

Details
Type:
Bug
Submit Date:
2008-02-05
Status:
Resolved
Updated Date:
2011-05-25
Project Name:
JDK
Resolved Date:
2008-03-04
Component:
core-svc
OS:
windows_2000
Sub-Component:
javax.management
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.2.1
Fixed Versions:
6u10 (b13)

Related Reports
Backport:

Sub Tasks

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
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.
                                     
2008-02-05
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.
                                     
2008-02-21
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.
                                     
2008-02-27



Hardware and Software, Engineered to Work Together