1. 程式人生 > >註意鎖標記是自己不會自動釋放,必須有通知

註意鎖標記是自己不會自動釋放,必須有通知

bounds tof rgs bound text nds package cep 使用

釋放鎖標記只有在Synchronized代碼結束或者調用wait()。

註意鎖標記是自己不會自動釋放,必須有通知。

註意在程序中判定一個條件是否成立時要註意使用WHILE要比使用IF要嚴密。

WHILE會放置程序饒過判斷條件而造成越界。

 1 package TomTexts;
 2 
 3 public class TomTexts_40 {
 4      public static void main(String args[])
 5      {
 6     try 
 7     {
 8     int i = args.length;
 9     System.out.println("i ="+i);
10 int j=5/i; 11 int k[]={ 1,2,3 }; 12 k[5]=0; 13 } 14 catch(ArithmeticException e) 15 { 16 System.out.println("被零除: " + e); 17 } 18 catch(ArrayIndexOutOfBoundsException e) 19 { 20 System.out.println("Array index out of bound exception: " + e); 21 } 22
System.out.println("執行catch塊後的語句塊"); 23 } 24 25 }

註意鎖標記是自己不會自動釋放,必須有通知