带返回值的函数如何在内部同步?

mac2022-06-30  21

《Java线程》第三版中找到的一个例子(见P163):

pubilc  int getCorrectNum( int c) {      synchronized(correctChars) {         Integer key =  new Integer(c);         Integer num = (Integer)correctChars.get(key);          if(num ==  null) {              return 0;         }           return num.intValue();     }

}

 原来synchronized块可以直接把返回语句包括其中。

转载于:https://www.cnblogs.com/cuizhf/archive/2011/09/22/2185407.html

最新回复(0)