System類詳解-2 exit gc runFinalization identityHashCode
阿新 • • 發佈:2019-01-05
System類詳解
0.說明 :這篇寫System類還沒有分析完的問題 ,主要解決一下幾個問題
- exit(int) 方法
- gc方法
- runFinalization方法
- identityHashCode
--------------------接下來深入分析一下exit方法--------------- 廢話不說,上圖
可以看出,起決定性作用的是Shutdown.exit方法,接下來我們分析這個方法---------------------------------不在這分析了令起一篇blog分析,Runtime,ApplicationShutdown ,Shutdown之間的關係 2.gc 等價於Runtime.getRuntime().gc 呼叫這種方法表明,Java虛擬機器花費大量的工作來回收未使用的物件,以便使它們當前佔用的記憶體可供快速重用。 當控制從方法呼叫返回時,虛擬機器已盡最大努力回收所有丟棄的物件
3.runFinalization ------會有一片部落格詳細介紹,區分runFinalization和gc方法的區別 4.identityHashCode
Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(). The hash code for the null reference is zero.
-----解釋:不管類有沒有重寫Object的hashCode方法,identityHashCode都返回通過預設的hashCode產生的值,也就是說identityHashCode的結果和Object類中的hashCode的結果是一樣的-------換句話說,不管你的類是否有重寫Object類中的hashCode方法,identityHashCode始終返回和Object中的hashCode一樣的結果。對於null物件,identityHashCode返回零。