- Java.lang 包类
- Java.lang - 首页
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang 包其他内容
- Java.lang - 接口
- Java.lang - 错误
- Java.lang - 异常
- Java.lang 包有用资源
- Java.lang - 有用资源
- Java.lang - 讨论
Java SecurityManager getThreadGroup() 方法
描述
Java SecurityManager getThreadGroup() 方法返回在调用此方法时创建任何新线程的线程组。默认情况下,它返回当前线程的线程组。特定安全管理器应覆盖此方法以返回相应的线程组。
声明
以下是 java.lang.SecurityManager.getThreadGroup() 方法的声明
public ThreadGroup getThreadGroup()
参数
无
返回值
此方法返回新线程实例化的 ThreadGroup
异常
无
示例
我们的示例需要阻止每个命令的权限。设置了一个新的策略文件,该文件只允许创建和设置我们的安全管理器。该文件位于 C:/java.policy 中,包含以下文本:
grant { permission java.lang.RuntimePermission "setSecurityManager"; permission java.lang.RuntimePermission "createSecurityManager"; permission java.lang.RuntimePermission "usePolicy"; };
以下示例演示了 lang.SecurityManager.getThreadGroup() 方法的用法。
package com.tutorialspoint; public class SecurityManagerDemo { public static void main(String[] args) { // set the policy file as the system securuty policy System.setProperty("java.security.policy", "file:/C:/java.policy"); // create a security manager SecurityManager sm = new SecurityManager(); // set the system security manager System.setSecurityManager(sm); // get the thread group ThreadGroup con = sm.getThreadGroup(); // print the the thread group System.out.println("" + con); } }
输出
让我们编译并运行以上程序,这将产生以下结果:
Exception in thread "main" java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release at java.base/java.lang.System.setSecurityManager(System.java:430) at com.tutorialspoint.SecurityManagerDemo.main(SecurityManagerDemo.java:14)
注意 - Security Manager 自版本 17 起已弃用,并标记为即将移除。
java_lang_securitymanager.htm
广告