I have the following structure:
public void someMethod(){
//DO SOME STUFF
try{
doSomeProcessing();
}
catch (Exception e){
We wrote a library that includes a utility lazily load/call a method. It guarantees single usage semantics and preserves any thrown exceptions as you'd expect.
Usage is simple:
LazyReference heavyThing = new LazyReference() {
protected Thing create() {
return loadSomeHeavyData();
}
};
public void someMethod(){
//DO SOME STUFF
try{
doSomeProcessing();
}
catch (Exception e){
heavyThing.get();
doSomeProcessing();
}
}
All threads block on the get() and wait for the producer thread (the first caller) to complete.