This permits callers to reuse Repository instances across threads, by using incrementOpen() to indicate the instance is in use, and a matched close() to release the usage counter. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/lib/Repository.java | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index fb72b64..e3ac01b 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -54,6 +54,7 @@ import java.util.Map; import java.util.Set; import java.util.Vector; +import java.util.concurrent.atomic.AtomicInteger; import org.spearce.jgit.errors.IncorrectObjectTypeException; import org.spearce.jgit.errors.RevisionSyntaxException; @@ -85,6 +86,8 @@ * */ public class Repository { + private final AtomicInteger useCnt = new AtomicInteger(1); + private final File gitDir; private final RepositoryConfig config; @@ -721,11 +724,17 @@ private ObjectId resolveSimple(final String revstr) throws IOException { return r != null ? r.getObjectId() : null; } + /** Increment the use counter by one, requiring a matched {@link #close()}. */ + public void incrementOpen() { + useCnt.incrementAndGet(); + } + /** * Close all resources used by this repository */ public void close() { - objectDatabase.close(); + if (useCnt.decrementAndGet() == 0) + objectDatabase.close(); } /** -- 1.6.4.rc0.117.g28cb -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html