runOnce
Aleksey Shipilev
aleksey.shipilev at oracle.com
Tue Sep 25 02:45:32 PDT 2012
Hi guys,
This thread [1] makes me thinking if we want to introduce something like
runOnce() to record per-callsite invocation information. I.e. instead of
messing with maps and flags to guard this behavior, one can possibly do:
Runners.runOnce(() -> System.out.println("Boo!"));
...where runOnce will be desugared by Javac into indy call in which
bootstrap method calls the callee, and then emits the constant callsite
holding the result. This will effectively record the "invoked" property
into callsite, so that this code:
Runners.runOnce(() -> System.out.println("foo"));
Runners.runOnce(() -> System.out.println("bar"));
would yield:
foo
bar
It might be yet another convenient way to make singletons (err...
thread-safe identity caches), like:
public T getInstance() { return Runners.runOnce(() -> new T()); }
Was something like this considered before?
-Aleksey.
[1]
http://mail.openjdk.java.net/pipermail/lambda-dev/2012-September/006015.html
More information about the lambda-libs-spec-observers
mailing list