Is it possible to invoke a forceful garbage collection in java every time heap memory crosses a particular threshold ?
Java Garbage Collection after heap memory crosses a threshold
1.5k Views Asked by Jaharsh At
2
There are 2 best solutions below
1
Sergey Prokofiev
On
In theory yes, you could configure such behaviour. Exact details depend on used garbage collection alghoritm. For example, for CMS you can kick off GC when heap memory usage reaches 70%. Most probably you would also want to set initial and max memory limits.
-XX:+UseConcMarkSweepGC -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70
Hope it helps!
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in GARBAGE-COLLECTION
- JVM is functioning very differently with same flags
- Why WeakReference to a WeakRef object is not garbage collected?
- GC cleaning the object before calling onPictureTaken method
- Know what objects got garbage collected
- Practical case JVM tunning to avoid full GC
- GC overhead limit exceed when reading large file
- Can java string literals be garbage collected?. If Yes, how to prove it?
- G1 doesn't process soft references
- why do I have to swapCursor(null) in onLoaderReset?
- Is it safe to assume static variables never get cleared?
- JVM ClassUnloadingWithConcurrentMark flag
- Java 8 Metaspace - Avoid decrease
- node.js memory usage issue
- G1GC Strange behavior
- Exposing whether an application is undergoing GC via UDP
Related Questions in HEAP-MEMORY
- C++ Pointer Object Location
- Interpretation of java hprof histogram
- Application Verifier limits Heap Allocations by default?
- How do I release images and avoid outOfMemory exc-n when navigating back and forth between activities[android]
- Is an attempt to modify a const_cast-ed, but dynamically allocated constant object still undefined behavior?
- Constant container (map) - eliminate heap allocation
- OutOfMemoryError: Java heap space MultipartRequest
- Predictionio evaluation fails with empty.maxBy exception and training with java.lang.OutOfMemoryError
- Two versions of the same java program out of which one is throwing Out of Memory Error and other one is not. Not able to get to know why?
- Heap - How free bytes are tracked?
- AngularJs $scope.$destroy(). How to use?
- Segmentation fault - Invalid free unresolved - C
- Query, if a heap is executable
- WA_DeleteOnClose delete all members?
- How to find the default Java 1.4.2 heap size in AIX
Related Questions in JAVA-HEAP
- Heap Allocation in ZGC
- Trying to create a Mosaic in ImageJ and I get this Java error
- java.lang.OutOfMemoryError: Java heap space thrown from java.net.http.HttpClient
- Generating Java heap dump in Kubernetes container
- pyspark java heap space error when just retrieving data frame columns
- Recommended Java Heap Size for Commercial JMeter Project
- Java Garbage Collection after heap memory crosses a threshold
- JVM committed heap memory is more than Xmx
- How to fix the below Cassandara error in docker container
- Getting "java.lang.OutOfMemoryError" exception while running a cucumber test using java-selenium
- manage assigned memory size in Anylogic
- Memory size feasible via Virtual Memory vs RAM
- How much memory takes TreeMap<Long, Long> collection granularly?
- java heap error while reading a file line by line inside a while loop
- Java Heap Dump : How to find the objects/class that is taking memory by 1. io.netty.buffer.ByteBufUtil 2. byte[] array
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This already happens. For example in
G1GC, this is either when young space is full (for a minor collection) or whenInitiatingHeapOccupancyPercentis hit (for a major collection). Both of these are controlled via flags, so you can tell when exactly is a GC supposed to be triggered, IFF you really want that.In
Shenandoahthere isShenandoahGCHeuristicsthat will choose some heuristics (they do depend on the size too).If, on the the other hand, you want to do that programmatically (there are tools that do that already), you could write some code that would inspect the size of the heap (for example via
ManagementFactory::getMemoryPoolMXBeans) and then via an agent call. In general, you would need a very good reason to do this.