lazy initialization of memory structures will save cpu time and may defer the activation of other plug-ins 內(nèi)存結(jié)構(gòu)的滯后初始化可以節(jié)省cpu時(shí)間并延遲其他插件的激活。
Instead of double-checked locking, use the initialize-on-demand holder class idiom, which provides lazy initialization, is thread-safe, and is faster and less confusing than double-checked locking 不使用雙重檢查鎖定,而使用initialize-on-demandholderclassidiom,它提供了遲緩初始化,是線程安全的,而且比雙重檢查鎖定更快且沒那么混亂:
This idiom derives its thread safety from the fact that operations that are part of class initialization, such as static initializers, are guaranteed to be visible to all threads that use that class, and its lazy initialization from the fact that the inner class is not loaded until some thread references one of its fields or methods 這個(gè)idiom由屬于類初始化的操作(如靜態(tài)初始化器)保證對(duì)使用這個(gè)類的所有線程都是可見的這一事實(shí)衍生其線程安全性,內(nèi)部類直到有線程引用其字段或者方法時(shí)才裝載這一事實(shí)衍生出遲緩初始化。
In addition to inconsistent synchronization, a number of other detectors for common threading errors are included, such as waiting on a monitor with two locks held which, while not necessarily a bug, could cause a deadlock, using the double-checked locking idiom, incorrect lazy initialization of nonvolatile fields, invoking 除了inconsistentsynchronization之外,findbugs還包含其他很多用于檢測(cè)常見線程錯(cuò)誤的檢測(cè)器,如在加鎖兩次的情況下等待監(jiān)視器(這雖然不一定是bug,但是可能導(dǎo)致死鎖),使用雙檢測(cè)加鎖模式,不正確地初始化非易失性的域,對(duì)線程調(diào)用