classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] FYI: DefaultStyledDocument fixlet


From: Mark Wielaard
Subject: Re: [cp-patches] FYI: DefaultStyledDocument fixlet
Date: Mon, 19 Dec 2005 16:47:54 +0100

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]