Note that there are some explanatory texts on larger screens.

plurals
  1. POatomic blocks in Java for matched data
    primarykey
    data
    text
    <p>A library I'm writing has a class implementing a two dimensional map and also provides, for efficient reading, smaller maps for the row/column views. So far all methods have been overridden so that any change in the main map are mirrored in the sub maps and vice versa. The problem comes in concurrent operation.</p> <p>Ideally a removal of an item from the master map will simultaneously remove the item from the respective row and column maps, but this is of course impossible. For example in my put function:</p> <pre><code>public synchronized Cell put(Duple&lt;Integer, Integer&gt; key, Cell arg1){ //preprocessing, detecting the row/col, creating row/col if not present yet, etc. Cell outcell = super.put(key, arg1); rowArr.putPriv(key.getElem2(), arg1); colArr.putPriv(key.getElem1(), arg1); arg1.assignCell(this, key); return outCell; } </code></pre> <p>While it is perfectly acceptable for simultaneous reads of the map and even concurrent modification is not an issue (except for the creation/removal of rows/columns which needs remove and put to be synchronized), but The 4 stages of modification (super.put, the row and column puts, and the cell location update) need to be atomic to ensure it's not possible to read unmatched data. </p> <p>What are my options? As far as I've found from my searching it's not possible to create an atomic sequence of statements in Java, and synchronisation isn't going to work unless I synchronise all my functions (which prevents concurrent reads, and I would need locks on multiple items). I know the principles of (but am not particularly practiced in) basic semaphore concepts, but don't see any simple ways to make a lock-on-write semaphore without massive complexity, particularly if I don't want to have massive waits for a writing slot. What additional options do I have?</p> <p>Note: due to the project I'm on I cannot use derivative languages such as groovy but can only use standard Java 1.6u24, without 3rd party libraries. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload