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 | <CAL465RHvM976J9G7+A+yzoHVp6hSRAVP4Na5ogNyjc4jgb1NeQ@mail.gmail.com> |
Keep a reference to the InstanceContent and synchronize on it. It should work as a common lock. Boris 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()? > > > > >