Bill Roper (billroper) wrote,
Bill Roper

All Meetings, All the Time

Back to the Loop again today for another round of meetings.

I did manage to spend a few more minutes on the locking scheme for the server-side of my Java code. At this point, I'm looking at having all of the lockable objects on the server define three inner classes: the first being an immutable class that holds all of the data for the mutable outer class, the second being a private class that provides a locator / index for the objects so that you can find them with a key, the third being a public class that allows you to obtain either a read lock or a write lock and that will give you access to either the immutable inner class or the mutable outer class, depending on the type of lock that you've obtained.

So in skeleton form, it would look like this:
public class MyClass implements LockableObject {
  public class Const {
    boolean    member;

    Const( boolean member ) {
      this.member = member;

    boolean getMember() {
      return this.member;

  private class MyIndex implements Index< Key, MyClass > {
    MyClass find( Key key ) {
      ... implementation details and other useful operations elided
      return object;

  public class Lock {
    Key       key;            // key to use with the index to locate the class instance
    LockType  readOrWrite;    // enum defined elsewhere (READ/WRITE)
    MyClass   object;         // the object, once we've located and locked it, else null

    public Lock( Key key, LockType readOrWrite ) {
      this.key = key;
      this.readOrWrite = readOrWrite;

    public boolean lock() {
      ... probably uses tryLock() etc on ReentrantReadWriteLock
      return success;

    public MyClass get() {
      if ( isLockedForWrite()) { 
        return object;

      return null;

    public MyClass.Const getConst() {
      if ( isLockedForWrite() || isLockedForRead()) {
        return object.Const;   // is this vaguely the right syntax?

      return null;

Ok, that's an awful mess of assumptions left out and I may have blown some of the syntax, as I haven't actually tried to compile this yet, but it looks like the right idea.

I think.
Tags: java, musings, work

  • Time for Rebuilding

    Well, there's nothing like research. Having determined that DDR5 is going to carry a substantial price premium over DDR4 memory for at least a year…

  • Driven Wild

    The studio computer continues to misbehave in various ways. When I fired up Cubase today, I got a lot of nasty, blocky video, despite having cleaned…

  • Some Old Doggerel

    I recall having mangled a CSN tune many years ago on the way to Contraption. Like that convention, the particular co-worker whose code I was digging…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded