Non-atomic increment operation on volatile field ackBytes in class ClientConsumerImpl
-------------------------------------------------------------------------------------
Key: JBMESSAGING-1792
URL:
https://jira.jboss.org/jira/browse/JBMESSAGING-1792
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 ClientConsumerImpl, field "ackBytes" is declared as volatile int, in
method acknowledge(xxx), ackBytes += message.getEncodeSize(); is seen, which is a
three-step (read->modify->write) non-atomic operation. Volatile keyword only
guarantees variable visibility, but not atomicity, so statement "ackBytes +=
message.getEncodeSize();" invoked by multiple threads can result to race condition
and incorrect result. It's suggested to use synchronized block to protect
"ackBytes += message.getEncodeSize();" 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