title: Java Synchronisation - Do I need it for this simple method?
body: <p>I have a simple method which is called from multiple threads;</p>
  
  <pre><code>@Override
  public Bitmap getFullBitmap(Filter f, ProgressCallback&lt;String&gt; pc) {
      // Requires synchronisation?
      Bitmap bitmap = fullMap.get(f.id);
      if(bitmap == null){
          f.setProgressCallback(pc);
          bitmap = f.e.evaluate(currentBitmap);
          fullMap.put(f.id, bitmap);
      }
      return bitmap;
  }
  </code></pre>
  
  <p>As none of the objects used are fields of the class (Apart from fullMap) is it ok just to call this or might one thread change the value of <strong>bitmap</strong> for example, while the method is executing?</p>
  
  <p>fullMap is a SoftHashMap which maintains SoftReferences of Bitmap objects indexed but the Filter's id that was used to create it. If that makes any sense.</p>
  
  <p>I haven't had any problems but I thought I might need it.</p>
  
  <p>Please ask for clarification if this is not clear, the question makes sense in my head ;)</p>
  
  <p><strong>EDIT</strong></p>
  
  <ul>
  <li>currentBitmap is an object of type Bitmap, there is one bitmap in the system which is considered current and it's managed by this class.</li>
  <li>This code forms a very basic cache,
  the bitmap returned will always be
  the same for each id and is not
  modified outside of this method.</li>
  <li>By using Soft References in a
  SoftHashMap as descibed by <a href="http://www.javaspecialists.eu/archive/Issue098.html" rel="nofollow noreferrer">Dr
  Heinx</a> and a FIFO queue of hard
  references for the 10 most recently
  added I hope to avoid expensive calls
  to f.e.evaluate. That being said, the
  call f.e.evaluate will return an
  identical bitmap object if it is
  given the same input. After some
  thought it seems that synchronizing
  the method is a good idea as nothing
  positive comes of two threads
  executing this code for the same
  filter.</li>
  <li>In addition I made bitmap final as it
  shouldn't be mutated after creation.</li>
  </ul>
  
  <p>Many thanks!
  Gav</p>