diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/SysJob.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/SysJob.java index 5a7d58fc71..283374c080 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/SysJob.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/SysJob.java @@ -31,7 +31,11 @@ public V call() throws Exception { @Override protected void done() { - this.save(); + try { + this.save(); + } finally { + super.done(); + } } @Override diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/UserJob.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/UserJob.java index f00cf44809..bc3ba03724 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/UserJob.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/UserJob.java @@ -31,7 +31,11 @@ public V call() throws Exception { @Override protected void done() { - this.save(); + try { + this.save(); + } finally { + super.done(); + } } @Override diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java index 8bec1645ea..ce3d26c644 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskCallable.java @@ -22,6 +22,7 @@ import java.util.Date; import java.util.concurrent.Callable; +import org.apache.tinkerpop.gremlin.structure.Transaction; import org.slf4j.Logger; import com.baidu.hugegraph.HugeException; @@ -48,13 +49,20 @@ public TaskCallable() { } protected void done() { - // Do nothing, subclasses may override this method + this.closeTx(); } protected void cancelled() { // Do nothing, subclasses may override this method } + protected void closeTx() { + Transaction tx = this.graph().tx(); + if (tx.isOpen()) { + tx.close(); + } + } + public void setMinSaveInterval(long seconds) { E.checkArgument(seconds > 0, "Must set interval > 0, bug got '%s'", seconds);