aspose file tools*
The moose likes Java in General and the fly likes GC and Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "GC and Timer" Watch "GC and Timer" New topic
Author

GC and Timer

Harsha Hegde
Greenhorn

Joined: Jan 12, 2009
Posts: 17

Hi Experts,
I was trying to build an application (which will run in a JEE environment) where I have a LinkedBlockingQueue and 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
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

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.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19002
    
  40

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.

Henry



Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

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.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19002
    
  40

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.


Sure...

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.


Other terms....

"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.

Henry
Harsha Hegde
Greenhorn

Joined: Jan 12, 2009
Posts: 17

Thanks a lot Stephan and Henry. Henry's reply worried me a bit. what i infer is in a high load system no timer application is reliable is this true, how is it managed then?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC and Timer