Improved log and configurable interval for eliminate pool thread
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@15219 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4cf1a9f3f4
commit
82f3d44967
|
@ -22,7 +22,11 @@
|
||||||
type="java.lang.Long"
|
type="java.lang.Long"
|
||||||
override="false" />
|
override="false" />
|
||||||
|
|
||||||
|
<environment
|
||||||
|
name="temporaryResourceSweeperIntervalInMs"
|
||||||
|
value="480000"
|
||||||
|
type="java.lang.Long"
|
||||||
|
override="false" />
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<environment
|
<environment
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||||
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
||||||
|
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -15,35 +16,31 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
||||||
*/
|
*/
|
||||||
public class EliminatePoolingThread extends Thread {
|
public class EliminatePoolingThread extends Thread {
|
||||||
|
|
||||||
private final long sleepTime = 60000;
|
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");;
|
||||||
|
|
||||||
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
|
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
|
||||||
|
|
||||||
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
|
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class);
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
boolean noErrors = true;
|
boolean noErrors = true;
|
||||||
|
|
||||||
while (noErrors) {
|
while (noErrors) {
|
||||||
try {
|
try {
|
||||||
this.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {}
|
||||||
}
|
|
||||||
|
|
||||||
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
|
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
synchronized (stack) {
|
synchronized (stack) {
|
||||||
int numRes = stack.size();
|
int numRes = stack.size();
|
||||||
while (stack.size() > 0) {
|
while (stack.size() > 0) {
|
||||||
Pair c = stack.remove(stack.size() - 1);
|
Pair c = stack.remove(stack.size() - 1);
|
||||||
logger.trace("checking resource for deletion " + c.resource.getID());
|
logger.trace("checking resource for deletion " + c.resource.getID());
|
||||||
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
|
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
|
||||||
if ((timestamp >= c.lifetime)) {
|
if (timestamp >= c.lifetime) {
|
||||||
try {
|
try {
|
||||||
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
|
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
|
||||||
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
|
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
|
||||||
|
@ -55,7 +52,6 @@ public class EliminatePoolingThread extends Thread {
|
||||||
tmpStack.offer(c); // re-insert the resource in the list
|
tmpStack.offer(c); // re-insert the resource in the list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
|
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
|
||||||
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
|
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
|
||||||
stack.addAll(tmpStack);
|
stack.addAll(tmpStack);
|
||||||
|
|
Loading…
Reference in New Issue