The same call site may be used in several places at once.
{@code MethodType MT_str2 = MethodType.methodType(String.class, String.class); MethodHandle MH_cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class)); MethodHandle MH_dear = MethodHandles.insertArguments(MH_cat, 1, ", dear?"); MethodHandle worker2 = MethodHandles.filterReturnValue(MH_name, MH_dear); assertEquals("Fred, dear?", (String) worker2.invokeExact()); name.setTarget(MethodHandles.constant(String.class, "Wilma")); assertEquals("WILMA", (String) worker1.invokeExact()); assertEquals("Wilma, dear?", (String) worker2.invokeExact());}
Non-synchronization of target values: A write to a mutable call site's target does not force other threads to become aware of the updated value. Threads which do not perform suitable synchronization actions relative to the updated call site may cache the old target value and delay their use of the new target value indefinitely. (This is a normal consequence of the Java Memory Model as applied to object fields.)
The {@link #syncAll syncAll} operation provides a way to force threadsto accept a new target value, even if there is no other synchronization.
For target values which will be frequently updated, consider using a {@linkplain VolatileCallSite volatile call site} instead. @author John Rose, JSR 292 EG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|