Module java.base

Class VolatileCallSite


  • public class VolatileCallSite
    extends CallSite
    A VolatileCallSite acts as though its target MethodHandle were a volatile variable. This CallSite sub-class should be used if the changes to the target are frequent or if changes must be immediately observed by all threads, even if the setTarget(MethodHandle) occurs in a different thread.

    Since VolatileCallSite's target is defined as though it were a volatile variable, there is no need for a method like MutableCallSite.syncAll(MutableCallSite[]) because every thread will always see a consistent view of the MethodHandle target.

    Since:
    1.7
    • Constructor Detail

      • VolatileCallSite

        public VolatileCallSite​(MethodHandle volatileTarget)
                         throws NullPointerException
        Create a VolatileCallSite with the same type as the volatileTarget and the initial target set to volatileTarget.
        Parameters:
        volatileTarget - - the target MethodHandle of the CallSite
        Throws:
        NullPointerException - - if the volatileTarget is null.
      • VolatileCallSite

        public VolatileCallSite​(MethodType type)
                         throws NullPointerException
        Create a VolatileCallSite with the MethodType type and an initial target that throws IllegalStateException.
        Parameters:
        type - - the permanent type of this CallSite.
        Throws:
        NullPointerException - - if the type is null.
    • Method Detail

      • getTarget

        public final MethodHandle getTarget()
        The target MethodHandle is returned as though by a read of a volatile variable.
        Specified by:
        getTarget in class CallSite
        Returns:
        the current target MethodHandle