JavaMemoryModel: Threading issues in my connection pool

From: David W. Smiley (dsmiley@mitre.org)
Date: Fri Sep 01 2000 - 10:53:03 EDT


  I just started following the issues related to the JMM at Bill's
site. I think that the problems with the JMM are very bad and their
resolve is very important to the advancement of Java. I am currently
building a JDBC connection pool implementation. It is complex in terms
of its multithreaded nature. There are a few techniques I am using to
avoid synchronization:
  double-check idiom
  copy on write
  no sync on read, sync on write --flags (ints/booleans used for state)
The slides I've read online thus far have made me concerned that I am
doing this all wrong. I've used "volatile" for instances that I check
for the double-check idiom, as well as for initialization/destruction
flag variables (but not for the copy-on-write field). So as a rule of
thumb, if there is some field that could potentially be seen by a thread
without acquiring a particular lock, then that member is made volatile.
Does this free me of synchronization problems _in current JVMs_ ? In
the future at least? I know my techniques are not good enough strictly
in terms of the current JMM _spec_, but I'm hoping the _implementations_
fare better.

-- David Smiley
   The MITRE Corporation

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:27 EDT