Java SecurityManager checkAwtEventQueueAccess()方法与示例
SecurityManager类的checkAwtEventQueueAccess()方法 (SecurityManager Class checkAwtEventQueueAccess() method)
checkAwtEventQueueAccess() method is available in java.lang package.
checkAwtEventQueueAccess()方法在java.lang包中可用。
checkAwtEventQueueAccess() method is used to access AWT(Abstract Window Toolkit) event queue by calling checkPermission with AWTPermission(“accessEventQueue”).
通过使用带有AWTPermission(“ accessEventQueue”)的checkPermission来调用checkAwtEventQueueAccess()方法来访问AWT(抽象窗口工具包)事件队列。
checkAwtEventQueueAccess() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
checkAwtEventQueueAccess()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
checkAwtEventQueueAccess() method may throw an exception at the time of accessing the AWT event queue.
在访问AWT事件队列时, checkAwtEventQueueAccess()方法可能会引发异常。
SecurityException – This exception may throw when the calling thread is not allowed to access the AWT event queue.
SecurityException-如果不允许调用线程访问AWT事件队列,则可能引发此异常。
Syntax:
句法:
public void checkAwtEventQueueAccess();Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is void, it returns nothing.
此方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example // of void checkAwtEventQueueAccess() // method of SecurityManager public class CheckAwtEventQueueAccess {public static void main(String[] args) {// By using setProperty() method is to set the policy property // with security managerSystem.setProperty("java.security.policy", "file:/C:/java.policy");// Instantiating a SecurityManager objectSecurityManager smgr = new SecurityManager();// By using setSecurityManager() method is to set the// security managerSystem.setSecurityManager(smgr);// By using CheckAwtEventQueueAccess() method is to check // that awt event queue is accessed or notsmgr.checkAwtEventQueueAccess();// Display the message when queue is acessibleSystem.out.println("Not Restricted..");} }Output
输出量
Exception in thread "main" java.security.AccessControlException: access denied ( java.awt.AWTPermission accessEventQueue)at java.security.AccessControlContext.checkPermission(AccessControlConte xt.java:264)at java.security.AccessController.checkPermission(AccessController.java: 427)at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)at java.lang.SecurityManager.checkAwtEventQueueAccess(SecurityManager.ja va:1398)at CheckAwtEventQueueAccess.main(CheckAwtEventQueueAccess.java:18)翻译自: https://www.includehelp.com/java/securitymanager-checkawteventqueueaccess-method-with-example.aspx
总结
以上是生活随笔为你收集整理的Java SecurityManager checkAwtEventQueueAccess()方法与示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: c#串口程序接收数据并打印_C#程序可打
- 下一篇: java对数组进行排序_用Java对数组