threadgroup

ThreadGroup类的checkAccess()方法 (ThreadGroup class checkAccess() method)

  • checkAccess() method is available in java.lang package.

    checkAccess()方法在java.lang包中可用。

  • checkAccess() method is used to check whether the currently running thread has permission to update the thread group or not.

    checkAccess()方法用于检查当前正在运行的线程是否具有更新线程组的权限。

  • checkAccess() method is not a static method so it is not accessible with the class name (i.e. this method is accessible with the class object only).

    checkAccess()方法不是静态方法,因此无法使用类名进行访问(即,只能使用类对象访问此方法)。

  • checkAccess() method is a final method so it is not overridable (i.e. this method is not overridable in child class).

    checkAccess()方法是最终方法,因此它不可重写(即,该方法在子类中不可重写)。

  • This method may throw an exception at the time of accessing a thread group.

    访问线程组时,此方法可能会引发异常。

    SecurityException: In this exception when the current thread is not authorized to access the thread group when the security manager exists.

    SecurityException:在存在安全管理器的情况下,当当前线程无权访问线程组时,发生此异常。

Syntax:

句法:

    public final void checkAccess();

Parameter(s):

参数:

  • This method does not accept any parameter.

    此方法不接受任何参数。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回类型为void ,它不返回任何内容。

Example:

例:

// Java program to demonstrate the example of
// checkAccess () method of ThreadGroup Class.
import java.lang.*;
class CheckAccess extends Thread {// Override run() of Thread class
public void run() {String name = Thread.currentThread().getName();
System.out.println(name + " " + "finish executing");
}
}
public class Main {public static void main(String[] args) {CheckAccess ca = new CheckAccess();
try {// We are creating an object of ThreadGroup class
ThreadGroup tg1 = new ThreadGroup("ThreadGroup 1");
ThreadGroup tg2 = new ThreadGroup("ThreadGroup 2");
// We are creating an object of Thread class and
// we are assigning the ThreadGroup of both the thread
Thread th1 = new Thread(tg1, ca, "First Thread");
Thread th2 = new Thread(tg2, ca, "Second Thread");
// Calling start() method with Thread class object
// of Thread class
th1.start();
th2.start();
// Here we are checking access of ThreadGroup
try {tg1.checkAccess();
System.out.println(tg1.getName() + " " + "has access");
tg2.checkAccess();
System.out.println(tg2.getName() + " " + "has access");
} catch (SecurityException se) {System.out.println(se.getMessage());
}
th1.join();
th2.join();
} catch (Exception ex) {System.out.println(ex.getMessage());
}
}
}

Output

输出量

E:\Programs>javac Main.java
E:\Programs>java Main
ThreadGroup 1 has access
ThreadGroup 2 has access
First Thread finish executing
Second Thread finish executing

翻译自: https://www.includehelp.com/java/threadgroup-class-checkacess-method-with-example.aspx

threadgroup

threadgroup_Java ThreadGroup类的checkAccess()方法和示例相关推荐

  1. threadgroup_Java ThreadGroup toString()方法与示例

    threadgroup ThreadGroup类的toString()方法 (ThreadGroup Class toString() method) toString() method is ava ...

  2. threadgroup_Java ThreadGroup list()方法与示例

    threadgroup ThreadGroup类的list()方法 (ThreadGroup Class list() method) list() method is available in ja ...

  3. java.util.zip 用法,Java压缩文件工具类ZipUtil使用方法代码示例

    本文实例通过Java的Zip输入输出流实现压缩和解压文件,前一部分代码实现获取文件路径,压缩文件名的更改等,具体如下: package com.utility.zip; import java.io. ...

  4. java long valueof_Java Long类的valueOf()方法及示例

    语法:public static Long valueOf (long value); public static Long valueOf (String value); public static ...

  5. Java SecurityManager checkAccess()方法与示例

    Syntax: 句法: public void checkAccess (Thread th); public void checkAccess (ThreadGroup tg); SecurityM ...

  6. Java基础篇:为Box类添加一个方法

    尽管创建一个仅包含数据的类是相当不错的事情,但这样的情况很少发生.大部分情况是你将使用方法存取由类定义的实例变量. 事实上,方法定义大多数类的接口.这允许类实现函数可以把内部数据结构的特定布局隐蔽到方 ...

  7. ulp通信_Java Math类ulp()方法及示例

    ulp通信 数学类ulp()方法 (Math class ulp() method) ulp() method is available in java.lang package. ulp()方法在j ...

  8. Java Math类toDegrees()方法与示例

    数学类toDegrees()方法 (Math class toDegrees() method) toDegrees() method is available in java.lang packag ...

  9. java 根据类名示例化类_Java类类getProtectionDomain()方法及示例

    java 根据类名示例化类 类class getProtectionDomain()方法 (Class class getProtectionDomain() method) getProtectio ...

最新文章

  1. oss2模块和aliyun oss连接
  2. Java异常的栈轨迹(Stack Trace)
  3. 一人之力,毁掉一个开发者活动
  4. dubbo的invoke命令_dubbo 调试服务telnet命令
  5. jakarta ee_Jakarta EE中的规范范围
  6. java 哈希一致算法_一致哈希算法Java实现
  7. react(94)--时间搜索传值规范
  8. 玩转算法值面试-第五章 -在链表中穿针引线
  9. Java面试——微服务
  10. oracle database link创建
  11. 从零开始写一个武侠冒险游戏-8-用GPU提升性能(3)
  12. Jmeter (二十五)逻辑控制器 之 Random Controller and Random order Controller
  13. linux jmeter 内存,怎么在Linux下改变JMeter内存
  14. 深入浅出统计学-第三章
  15. 数位板驱动(手绘板驱动),wintab 8192级压感,TabletDriver通用, 支持windows, mac系统
  16. 先进过程工业控制与组态软件
  17. 计算机应用基础word的课件,计算机应用基础之word2010课件
  18. 【世界最佳旅游win7主题】
  19. 耳鸣头晕是怎么回事?
  20. win10 tensorflow-gpu1.4 rtx2060 安装详细教程 fater-rcnn

热门文章

  1. iis架设aspx_在IIS6中配置html文件以ASPX方式工作
  2. 计算机辅助审计的特点是,浅谈新环境下计算机辅助审计的特点和应用_1
  3. 【SSM面向CRUD编程专栏 1】Spring简介 xml配置文件 依赖注入 数据注入
  4. 测试项目:车牌检测,行人检测,红绿灯检测,人流检测,目标识别
  5. 模型压缩 相关文章解读
  6. 介绍一下再Apache下的Tomcat负载均衡的一些使用问题
  7. Fusion组件库是如何支持多语言能力的
  8. python文件编码及执行
  9. Linux的标准I/O和管道
  10. Kingback小组冲刺博客