thread類的activeCount()方法判斷當前運行的線程是否有修改線程的權限。
用法
public final void checkAccess()
返回
它不返回任何值。
異常
SecurityException:如果不允許當前線程訪問該線程,則拋出此異常。
示例
public class JavaCheckAccessExp extends Thread
{
public void run()
{
System.out.println(Thread.currentThread().getName()+" finished executing");
}
public static void main(String arg[]) throws InterruptedException, SecurityException
{
// creating the thread
JavaCheckAccessExp t1 = new JavaCheckAccessExp();
JavaCheckAccessExp t2 = new JavaCheckAccessExp();
// this will call the run() method
t1.start();
t2.start();
// Check for access permission of current running thread
t1.checkAccess();
System.out.println(t1.getName() + " has access");
t2.checkAccess();
System.out.println(t2.getName() + " has access");
}
}
輸出:
Thread-0 has access Thread-1 has access Thread-0 finished executing Thread-1 finished executing
相關用法
- Java Thread currentThread()用法及代碼示例
- Java Thread toString()用法及代碼示例
- Java Thread interrupted()用法及代碼示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代碼示例
- Java Thread suspend()用法及代碼示例
- Java Thread destroy()用法及代碼示例
- Java Thread holdLock()用法及代碼示例
- Java Thread getContextClassLoader()用法及代碼示例
- Java Thread setContextClassLoader()用法及代碼示例
- Java Thread sleep()用法及代碼示例
- Java Thread getThreadGroup()用法及代碼示例
- Java Thread isInterrupted()用法及代碼示例
- Java Thread enumerate()用法及代碼示例
- Java Thread notify()用法及代碼示例
- Java Thread resume()用法及代碼示例
- Java Thread activeCount()用法及代碼示例
- Java Thread isDaemon()用法及代碼示例
- Java Thread setDaemon()用法及代碼示例
- Java Thread getId()用法及代碼示例
- Java Thread setName()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Thread checkAccess() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。