Hi Roman,

On Mon, 2005-12-19 at 13:59 +0000, Roman Kennke wrote:
> Also, I put this operation into a write lock as pointed out in the
> OReilly Swing book.


> +    writeLock();
>      int index = offset;
>      while (index < offset + length)
>        {
>          AbstractElement par = (AbstractElement) getParagraphElement(index);
> +        // If we have already seen this paragraph element, then exit the 
> loop.
> +        if (par.getEndOffset() + 1 == index)
> +          break;
> +
>          AttributeContext ctx = getAttributeContext();
>          if (replace)
>            par.removeAttributes(par);
>          par.addAttributes(attributes);
> -        index = par.getElementCount();
> +        index = par.getEndOffset() + 1;
>        }
> +    writeUnlock();

It would be good to always write these locking operations as:

writeLock();
try
  {
    // ...
  }
finally
  {
    writeUnlock();
  }

Just in case any (unchecked) exception is thrown between the lock and
the unlock part.

Cheers,

Mark

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to