线程类最终无效checkAccess() (Thread Class final void checkAccess())
This method is available in package java.lang.Thread.checkAccess().
软件包java.lang.Thread.checkAccess()中提供了此方法。
This method is used to check whether currently executing thread has permission to modify or not.
此方法用于检查当前正在执行的线程是否具有修改权限。
This method is final so we are not allowed to override this method in our class.
此方法是最终方法,因此不允许在类中重写此方法。
The return type of this method is void, it does not return anything.
此方法的返回类型为void ,它不返回任何内容。
This method does throw SecurityException if calling thread does not have permission to modify the thread and throw NullPointerException, if the thread parameter is null.
如果调用线程没有修改线程的权限,则抛出SecurityException ,如果thread参数为null,则抛出NullPointerException 。
Syntax:
句法:
final void checkAccess(){
}
Parameter(s):
参数:
We don't pass any object as a parameter in the method of the File.
我们不会在File方法中将任何对象作为参数传递。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回类型为void ,它不返回任何内容。
Java程序演示checkAccess()()方法的示例 (Java program to demonstrate example of checkAccess()() method)
/* We will use Thread class methods
so we are importing the package but it is not
mandate because it is imported by default
*/
import java.lang.Thread;
public class MainThread extends Thread {
public static void main(String[] args) throws Exception {
// creating two thread
MainThread mt1 = new MainThread();
MainThread mt2 = new MainThread();
// By using checkAccess() method is used to
// check whether current thread has permission
// to modify the thread or not
mt1.checkAccess();
mt2.checkAccess();
// Display current thread name with permission
System.out.println(mt1.getName() + " has access");
System.out.println(mt2.getName() + " has access");
}
}
Output
输出量
E:\Programs>javac MainThread.java
E:\Programs>java MainThread
Thread-0 has access
Thread-1 has access
翻译自: https://www.includehelp.com/java/thread-class-final-void-checkaccess-method-with-example.aspx