How to protect dynamic lookup content when it is changing?
"rsobies" <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[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()?