Berkeley CSUA MOTD:Entry 41389
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2006/1/16-18 [Computer/SW/Languages/Java] UID:41389 Activity:nil
1/16    Does anyone know how to query the maximum (or at least current) JVM
        heap size at runtime?  I'd like to be able to set the max JVM heap size
        (-Xmx512M) in a script and have my app sense that and use the number
        in sizing its caches.  Is there any good way to do this?
        \_ Runtime.{free,total,max}Memory() will give you the numbers you want.
           If this is for caches, you might also want to look into the
           SoftReference and WeakReference classes in java.lang.ref. -gm
           \_ Yeah, I've thought of WeakReferences for the next refactoring,
              but I'm worried about data I want to cache for a future similar
              query getting GC'd out from under me. -OP
              \_ Oh, yeah, thanks. -OP