-package org.simantics.db.impl;\r
-\r
-import java.lang.ref.WeakReference;\r
-\r
-public class MemWatch {\r
- public static boolean isLowOnMemory() {\r
- return isLowOnMemory;\r
- }\r
- private static boolean DBBUG = false;\r
- private static boolean isLowOnMemory = false;\r
- @SuppressWarnings("unused")\r
- private static MemWatch memWatch = new MemWatch();\r
- private Runtime runtime = Runtime.getRuntime();\r
- @SuppressWarnings("unused")\r
- private WeakReference<Watch> ref = new WeakReference<Watch>(new Watch());\r
- class Watch {\r
- @Override\r
- protected void finalize() throws Throwable {\r
- long fre = runtime.freeMemory();\r
- long tot = runtime.totalMemory();\r
- long max = runtime.maxMemory();\r
- if (tot < max || fre > max / 20) \r
- isLowOnMemory = false;\r
- else\r
- isLowOnMemory = true;\r
- if (DBBUG)\r
- System.err.println("Garbage was collected using " + Thread.currentThread().getName()\r
- + " fre=" + fre + " tot=" + tot + " max=" + max\r
- + " low=" + isLowOnMemory);\r
- ref = new WeakReference<Watch>(new Watch());\r
- super.finalize();\r
- }\r
- }\r
-}\r
+package org.simantics.db.impl;
+
+import java.lang.ref.WeakReference;
+
+public class MemWatch {
+ public static boolean isLowOnMemory() {
+ return isLowOnMemory;
+ }
+ private static boolean DBBUG = false;
+ private static boolean isLowOnMemory = false;
+ @SuppressWarnings("unused")
+ private static MemWatch memWatch = new MemWatch();
+ private Runtime runtime = Runtime.getRuntime();
+ @SuppressWarnings("unused")
+ private WeakReference<Watch> ref = new WeakReference<Watch>(new Watch());
+ class Watch {
+ @Override
+ protected void finalize() throws Throwable {
+ long fre = runtime.freeMemory();
+ long tot = runtime.totalMemory();
+ long max = runtime.maxMemory();
+ if (tot < max || fre > max / 20)
+ isLowOnMemory = false;
+ else
+ isLowOnMemory = true;
+ if (DBBUG)
+ System.err.println("Garbage was collected using " + Thread.currentThread().getName()
+ + " fre=" + fre + " tot=" + tot + " max=" + max
+ + " low=" + isLowOnMemory);
+ ref = new WeakReference<Watch>(new Watch());
+ super.finalize();
+ }
+ }
+}