froehlich 02/01/27 08:49:03
Modified: src/java/org/apache/cocoon/components/store
StoreJanitorImpl.java
Log:
fix bug submitted by Peter Hargreaves [[EMAIL PROTECTED]]:
quick and dirty hack to avoid endless loop running the gc all the
time.
Revision Changes Path
1.4 +39 -22
xml-cocoon2/src/java/org/apache/cocoon/components/store/StoreJanitorImpl.java
Index: StoreJanitorImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/StoreJanitorImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StoreJanitorImpl.java 26 Jan 2002 16:54:42 -0000 1.3
+++ StoreJanitorImpl.java 27 Jan 2002 16:49:03 -0000 1.4
@@ -27,11 +27,13 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Gerhard Froehlich</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
*/
-public class StoreJanitorImpl extends AbstractLoggable implements StoreJanitor,
- Configurable,
- ThreadSafe,
- Runnable,
- Startable {
+public class StoreJanitorImpl
+extends AbstractLoggable
+implements StoreJanitor,
+ Configurable,
+ ThreadSafe,
+ Runnable,
+ Startable {
private int freememory = -1;
private int heapsize = -1;
@@ -65,7 +67,8 @@
this.setFreememory(params.getParameterAsInteger("freememory",1000000));
this.setHeapsize(params.getParameterAsInteger("heapsize",60000000));
this.setCleanupthreadinterval(params.getParameterAsInteger("cleanupthreadinterval",10));
-
this.setPriority(params.getParameterAsInteger("threadpriority",Thread.currentThread().getPriority()));
+ this.setPriority(params.getParameterAsInteger( "threadpriority",
+ Thread.currentThread().getPriority()));
if ((this.getFreememory() < 1)) {
throw new ConfigurationException("StoreJanitorImpl freememory parameter
has to be greater then 1");
@@ -106,6 +109,8 @@
while (doRun) {
// amount of memory used is greater then heapsize
if (this.memoryLow()) {
+ int cnt = 0;
+
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("Invoking garbage collection, total
memory = "
+ this.getJVM().totalMemory() + ", free memory = "
@@ -118,10 +123,12 @@
+ this.getJVM().freeMemory());
}
synchronized (this) {
- while (this.memoryLow() && this.getStoreList().size() > 0) {
+ while (this.memoryLow()
+ && this.getStoreList().size() > 0
+ && cnt < 1) {
this.freeMemory();
+ cnt++;
}
- this.resetIndex();
}
}
try {
@@ -137,10 +144,22 @@
*/
private boolean memoryLow() {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Memory is low="
- + (this.getJVM().totalMemory() > this.getHeapsize() &&
this.getJVM().freeMemory() < this.getFreememory()));
+ this.getLogger().debug("JVM total Memory: " +
this.getJVM().totalMemory());
+ this.getLogger().debug("JVM free Memory: " +
this.getJVM().freeMemory());
+ }
+
+ if((this.getJVM().totalMemory() > this.getHeapsize())
+ && (this.getJVM().freeMemory() < this.getFreememory())) {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("Memory is low = true");
+ }
+ return true;
+ } else {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("Memory is low = false");
+ }
+ return false;
}
- return this.getJVM().totalMemory() > this.getHeapsize() &&
this.getJVM().freeMemory() < this.getFreememory();
}
/**
@@ -152,7 +171,8 @@
this.getStoreList().add(store);
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("Registering store instance");
- this.getLogger().debug("Size of StoreJanitor now:" +
this.getStoreList().size());
+ this.getLogger().debug("Size of StoreJanitor now:"
+ + this.getStoreList().size());
}
}
@@ -165,7 +185,8 @@
this.getStoreList().remove(store);
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("Unregister store instance");
- this.getLogger().debug("Size of StoreJanitor now:" +
this.getStoreList().size());
+ this.getLogger().debug("Size of StoreJanitor now:"
+ + this.getStoreList().size());
}
}
@@ -191,23 +212,22 @@
private void freeMemory() {
try {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("StoreJanitor freeing memory!");
this.getLogger().debug("StoreList size=" +
this.getStoreList().size());
- this.getLogger().debug("Index before=" + this.getIndex());
+ this.getLogger().debug("Actual Index position: " + this.getIndex());
}
if (this.getIndex() < this.getStoreList().size()) {
if(this.getIndex() == -1) {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Freeing at index=" +
this.getIndex());
+ this.getLogger().debug("Freeing Store: " + this.getIndex());
}
((Store)this.getStoreList().get(0)).free();
this.setIndex(0);
} else {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Freeing at index=" +
this.getIndex());
+ this.getLogger().debug("Freeing Store: " + this.getIndex());
}
- ((Store)this.getStoreList().get(this.getIndex())).free();
this.setIndex(this.getIndex() + 1);
+ ((Store)this.getStoreList().get(this.getIndex())).free();
}
} else {
if (this.getLogger().isDebugEnabled()) {
@@ -217,10 +237,7 @@
((Store)this.getStoreList().get(0)).free();
this.setIndex(0);
}
- this.freePhysicalMemory();
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Index after=" + this.getIndex());
- }
+ //this.freePhysicalMemory();
} catch(Exception e) {
this.getLogger().error("Error in freeMemory()",e);
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]