Author: chinthaka
Date: Tue Dec 20 21:51:35 2005
New Revision: 358218
URL: http://svn.apache.org/viewcvs?rev=358218&view=rev
Log:
SGCtxt and ServiceContexts are also garbage collected now. Eventhough this was
achieved using a thread initially, we thought better to minimize the number of
threads. So now this GC happens, whenever there is an addition to the
serviceGroupContextMap in the configuration context.
Another good news is that, I don't see any more memory leaks, except
SimpleConnectionThread objects. So all in all Axis2 seems good in terms of
memory ( at least for me :) ).
Removed:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
URL:
http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java?rev=358218&r1=358217&r2=358218&view=diff
==============================================================================
---
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
(original)
+++
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
Tue Dec 20 21:51:35 2005
@@ -20,16 +20,16 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.util.SGContextGarbageCollector;
import org.apache.axis2.util.UUIDGenerator;
import org.apache.axis2.util.threadpool.ThreadFactory;
import org.apache.axis2.util.threadpool.ThreadPool;
import java.io.File;
+import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
-import java.util.Timer;
/**
* This contains all the configuration information for Axis2.
@@ -47,19 +47,14 @@
private File rootDir;
private transient ThreadFactory threadPool;
+ // current time out interval is 30 secs. Need to make this configurable
+ private long serviceGroupContextTimoutInterval = 30 * 1000;
+
public ConfigurationContext(AxisConfiguration axisConfiguration) {
super(null);
this.axisConfiguration = axisConfiguration;
}
- private void startTimerTaskToTimeOutSGCtxt() {
- int delay = 5000; // delay for 5 sec.
- int period = 3000; // repeat every 3 sec.
- Timer timer = new Timer();
-
- timer.schedule(new SGContextGarbageCollector(serviceGroupContextMap, 5
* 1000), delay, period);
- }
-
protected void finalize() throws Throwable {
super.finalize(); //To change body of overridden methods use File |
Settings | File Templates.
}
@@ -88,11 +83,11 @@
ServiceContext serviceContext;
if (!isNull(serviceGroupContextId)
- && (serviceGroupContextMap.get(serviceGroupContextId) !=
null)) {
+ && (getServiceGroupContext(serviceGroupContextId) != null)) {
// SGC is already there
serviceGroupContext =
- (ServiceGroupContext)
serviceGroupContextMap.get(serviceGroupContextId);
+ getServiceGroupContext(serviceGroupContextId);
serviceContext =
serviceGroupContext.getServiceContext(messageContext.getAxisService().getName());
} else {
@@ -142,8 +137,12 @@
if (serviceGroupContextMap.get(id) == null) {
serviceGroupContextMap.put(id, serviceGroupContext);
+ serviceGroupContext.touch();
serviceGroupContext.setParent(this);
}
+
+ // this is the best time to clean up the SGCtxts that are not being
used anymore
+ cleanupServiceGroupContexts();
}
public AxisConfiguration getAxisConfiguration() {
@@ -186,9 +185,13 @@
return (ServiceContext) this.serviceContextMap.get(serviceInstanceID);
}
- public ServiceGroupContext getServiceGroupContext(String
serviceGroupContextId) {
+ public synchronized ServiceGroupContext getServiceGroupContext(String
serviceGroupContextId) {
if (serviceGroupContextMap != null) {
- return (ServiceGroupContext)
serviceGroupContextMap.get(serviceGroupContextId);
+ ServiceGroupContext serviceGroupContext = (ServiceGroupContext)
serviceGroupContextMap.get(serviceGroupContextId);
+ if (serviceGroupContext != null) {
+ serviceGroupContext.touch();
+ }
+ return serviceGroupContext;
}
return null;
@@ -244,6 +247,20 @@
threadPool = pool;
} else {
throw new AxisFault("Thread pool already set.");
+ }
+ }
+
+ private void cleanupServiceGroupContexts() {
+ synchronized (serviceGroupContextMap) {
+ long currentTime = new Date().getTime();
+ Iterator sgCtxtMapKeyIter =
serviceGroupContextMap.keySet().iterator();
+ while (sgCtxtMapKeyIter.hasNext()) {
+ String sgCtxtId = (String) sgCtxtMapKeyIter.next();
+ ServiceGroupContext serviceGroupContext =
(ServiceGroupContext) serviceGroupContextMap.get(sgCtxtId);
+ if ((currentTime - serviceGroupContext.getLastTouchedTime()) >
serviceGroupContextTimoutInterval) {
+ sgCtxtMapKeyIter.remove();
+ }
+ }
}
}
}