java.security 源码学习06 PrivilegedAction

1. 源码


/**
   A computation to be performed with privileges enabled.  The computation is
   performed by invoking {@code AccessController.doPrivileged} on the
   {@code PrivilegedAction} object.  This interface is used only for
   computations that do not throw checked exceptions; computations that
   throw checked exceptions must use {@code PrivilegedExceptionAction}
   instead.
 启用权限时执行的计算。通过在{@code PrivilegedAction}对象上调用
 {@code AccessController.doPrivileged}来执行计算。
 此接口仅用于不抛出已检查异常的计算;
 抛出已检查异常的计算必须使用{@code PrivilegedExceptionAction}。
 *
 * @see AccessController
 * @see AccessController#doPrivileged(PrivilegedAction)
 * @see PrivilegedExceptionAction
 */

public interface PrivilegedAction<T> {
    /**
       Performs the computation.  This method will be called by
       {@code AccessController.doPrivileged} after enabling privileges.

     执行计算。启用权限后,{@code AccessController.doPrivileged}将调用此方法。

       @return a class-dependent value that may represent the results of the
               computation. Each class that implements
               {@code PrivilegedAction}
               should document what (if anything) this value represents.
       @see AccessController#doPrivileged(PrivilegedAction)
       @see AccessController#doPrivileged(PrivilegedAction,
                                           AccessControlContext)
     */
    T run();
}

猜你喜欢

转载自blog.csdn.net/weixin_38389755/article/details/93743036