Non-atomic increment operation on volatile field lastReceivedCommandID in class
ChannelImpl
-------------------------------------------------------------------------------------------
Key: JBMESSAGING-1793
URL:
https://jira.jboss.org/jira/browse/JBMESSAGING-1793
Project: JBoss Messaging
Issue Type: Bug
Components: Messaging Core
Affects Versions: 2.0.0.beta4
Environment: OS: Redhat-5 Linux 2.6.18-92.el5
JDK: java version "1.6.0"
Java(TM) SE Runtime Environment (build pxi3260sr4-20090219_01(SR4))
IBM J9 VM (build 2.4, J2RE 1.6.0 IBM J9 2.4 Linux x86-32 jvmxi3260-20090215_29883 (JIT
enabled, AOT enabled)
J9VM - 20090215_029883_lHdSMr
JIT - r9_20090213_2028
GC - 20090213_AA)
JCL - 20090218_01
Reporter: Daniel Luo
In class ChannelImpl, field "lastReceivedCommandID" is declared as volatile int,
in method confirm(xxx), lastReceivedCommandID++; is seen, which is a three-step
(read->modify->write) non-atomic operation. Volatile keyword only guarantees
variable visibility, but not atomicity, so statement "lastReceivedCommandID++;"
invoked by multiple threads can result to race condition and incorrect result. It's
suggested to use synchronized block to protect "lastReceivedCommandID++;" or
AtomicInteger class from java.util.concurrent package to do atomic increment operation.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira