當JVM在進行垃圾回收(Garbage Collection, GC)時,會導致Stop the World。
JoJo's Bizarre Adventure - Stardust Crusaders - Dio Za Warudo (ザ・ワールド)
Stop-the-world的意思是,應用程式中除了處理垃圾回收的執行緒以外的全部執行緒會被暫停,直到垃圾回收結束後才會繼續執行的現象。
不論是Minor GC或Major GC都會導致stop-the-world。不過Minor GC的時間很短,回收速度很快,所以stop-the-world的影響不大;問題是Major GC要回收的物件很多,耗費時間很長,stop-the-world會導致應用程式出現卡頓的甚至是無回應的狀況。而Major GC stop-the-world的長短受所使用的垃圾回收器(Garbage collector)影響。
下面節錄Oracle官方文件 - Java Garbage Collection Basics的說明。
Stop the World Event - All minor garbage collections are "Stop the World" events. This means that all application threads are stopped until the operation completes. Minor garbage collections are always Stop the World events.
The Old Generation is used to store long surviving objects. Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually the old generation needs to be collected. This event is called a major garbage collection.
Major garbage collection are also Stop the World events. Often a major collection is much slower because it involves all live objects. So for Responsive applications, major garbage collections should be minimized. Also note, that the length of the Stop the World event for a major garbage collection is affected by the kind of garbage collector that is used for the old generation space.
參考:
沒有留言:
張貼留言