public synchronized T applyEx ( ) { // Have we produced our value yet? if ( producer != null ) { // produce our value. value = producer . apply ( ) ; // Delete the producer to 1. mark the work done and 2. free resources. producer = null ; } // We're clear to return the lazily computed value. return value ; }
This whole method is synchronized on the advice of Goetz2006 p . 347