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來調(diào)用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()方法是一種非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
checkAwtEventQueueAccess() method may throw an exception at the time of accessing the AWT event queue.
在訪問AWT事件隊列時, checkAwtEventQueueAccess()方法可能會引發(fā)異常。
SecurityException – This exception may throw when the calling thread is not allowed to access the AWT event queue.
SecurityException-如果不允許調(diào)用線程訪問AWT事件隊列,則可能引發(fā)此異常。
Syntax:
句法:
public void checkAwtEventQueueAccess();Parameter(s):
參數(shù):
It does not accept any parameter.
它不接受任何參數(shù)。
Return value:
返回值:
The return type of this method is void, it returns nothing.
此方法的返回類型為void ,不返回任何內(nèi)容。
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
總結(jié)
以上是生活随笔為你收集整理的Java SecurityManager checkAwtEventQueueAccess()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c#串口程序接收数据并打印_C#程序可打
- 下一篇: 分布式ID生成的9种方法,特好用!