| 通过下面的两种方式都能实现线程互斥,但是synchronized (this)和synchronized (Outputer.class)两种方式的话,对于第一种用this和第二种用Outputer.class加锁,有什么不同或者相同的地方?各位力士,帮忙分析解释一下,谢谢了!!!   //互斥方式1   public synchronized void output(String str){       synchronized (this) {  //??          int length = str.length();          for(int i = 0; i < length; i++){              System.out.print(str.charAt(i));          }          System.out.println();       }   } 
 
   //互斥方式2   public static synchronized void output(Stringstr){//需将内部类Outputer申明为static       synchronized (Outputer.class) {  //??          int length = str.length();          for(int i = 0; i < length; i++){              System.out.print(str.charAt(i));          }          System.out.println();       }   }  } 
 |