1 package org.simantics.db.common;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.service.QueryControl;
6 public class QueryMemoryWatcher {
9 final QueryControl support;
14 boolean collecting = false;
16 public QueryMemoryWatcher(ReadGraph graph, int allowedQueries) {
17 this(graph, allowedQueries, 0.5, 10);
20 public QueryMemoryWatcher(ReadGraph graph, int allowedQueries, double ratio, int stopTime) {
21 this.support = graph.getService(QueryControl.class);
22 baseline = support.count();
23 highLimit = baseline + allowedQueries;
24 lowLimit = baseline + (int)(allowedQueries*ratio);
27 //System.err.println("QueryMemoryWatcher started with " + baseline + " queries.");
30 public void maintain() {
31 long current = support.count();
33 if(current > lowLimit) support.gc(graph, stopTime);
35 // System.err.println("QueryMemoryWatcher stops collecting");
39 if(current > highLimit) {
40 // System.err.println("QueryMemoryWatcher starts collecting");