Java Thread类的最终void checkAccess()方法(带示例)

线程类最终无效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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值