I was trying to build an application (which will run in a JEE environment) where I have a LinkedBlockingQueueand some data get added. I try to empty this queue on two conditions 1-> when queue is full 2-> when there is a time out. I start a timer when i add the first element and reset i empty the queue. Question bothering me is, is there any side effect on the running timer when the stop-the-world GC runs? If so then what is is and what is the alternative?
Stephan van Hulst wrote:As far as I know, GC runs in a different thread. It doesn't pause anything. Maybe the fact that it takes up processor time will affect the resolution of the timer, but it should hardly bother you.
The newpar generation collector is parallel -- and not concurrent... So it will "stop-the-world". The concurrent tenure generation collector is concurrent, meaning not stop-the-world, but under very high throughput and heap, it can fail. This will cause the standard old generation gc to run, which will "stop-the-world". Personally, I wouldn't worry about it too much, as the collector is fairly quick, unless you are talking about about a heap greater than 4gig with allocation rates in the hundreds of megs per second.
So, the timer may be late to start. Its "stop-the-world", everything will be frozen during this period.
Stephan van Hulst wrote:Henry, could you elaborate on this a bit? What are these different collectors you talk of? I'm familiar with mark and sweep, but not with the terms you mentioned.
A mark and sweep collector does collection in multiple passes. It traverses the heap and mark everything that is reachable; and then in later passes, it compacts the heap. This pass is the sweep part. Objects are moved only to fill gaps left by unreachable objects.
The other type of collector is the copy collector. It does collection by moving everything that is reachable. The heap is cut in half, and objects are moved from half to half during each cycle. What doesn't move is collected.
A generational collector is not really a collector. It is a technique of using multiple collectors. A new object is placed in a "new" heap, where it is managed by a collector. And if it survives too many cycles, it gets promoted to the tenured heap, where it is managed by another collector. With the Sun JVM, the new generation is a copy collector and the tenured generation is a mark and sweep collector.
"Parallel" means that the collector is threaded -- and will use many processors. "Concurrent" means that the collector will run concurrently with the application. If the collector is not concurrent, it will stop-the-world (the application) until it is finished. Of all the JVMs available today, there is only one GC that is both concurrent and parallel; and that is the Azul JVM.
The Sun JVM actually have many collectors. There are quite a few options for both the new and old generational heaps.