Re: How to protect dynamic lookup content when it is changing?

Boris Heithecker <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CAL465REL2ia__hNrdmDxE0-_msB0pb53JD6O-Cm_Ym9i_n6=mQ@mail.gmail.com>
Keep a reference to the InstanceContent and synchronize on it. It should
work as a common lock.

Am 11.10.2016 13:33 schrieb "rsobies" <[email protected]>:

> i would like to block accesing lookup content when another thread is
> puting into lookup.
> here is an example
>
>
> Code:
>
> public class MyNode extends AbstractNode {
>
>     private InstanceContent instanceContent = new InstanceContent();
>
>     public MyNode(SomeKey key) {
>         this(key, new InstanceContent());
>     }
>
>     private CarNode(SomeKey key, InstanceContent ic) {
>         super(Children.LEAF, new AbstractLookup(ic));
>
>         this.instanceContent = ic;
>         instanceContent.add(key);
>     }
>
>     public void setNewKey(SomeKey key) {
>         Collection<? extends SomeKey> lookupAll =
> getLookup().lookupAll(SomeKey.class);
>         for (Object item : lookupAll) {
>             remove(item);
>         }
>
>  //at this time lookup is empty, if another thread tries to get content,
> it gets null
>
>         instanceContent.add(key);
>     }
> }
> }
>
>
>
>
> is there an elegant way to block getLookup().lookup(SomeKey.class) during
> execution of setNewKey()?
>
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.