[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [jgit-dev] JGit thread safety
- From: Shawn Pearce <spearce@xxxxxxxxxxx>
- Date: Thu, 18 Apr 2013 08:54:58 -0700
- Delivered-to: firstname.lastname@example.org
On Thu, Apr 18, 2013 at 4:26 AM, Dimitar Georgiev
> Are local JGit operations such as commit and add thread-safe?
No. There is only one working directory. JGit assumes the caller has
managed synchronization with the working directory, since there is
> I am building
> a homegrown content management solution and am using JGit Command API behind
> the scenes. Requests to JGit can come from multiple (HTTP) threads and I was
> wondering whether having no programmatic locking around this could result in
> data corruption / race conditions.
> Also what is the expected results when there is a simultaneous commit /
Don't use a working directory. The internals are thread-safe for
accessing the local repository's object database and references. If
all edits are done in-memory using the lower-level API you can do this
completely thread-safe and without the local working directory. It
requires using the DirCache to manipulate what is in the repository's
file listing, and CommitBuilder to fill out a commit. These are the
primitives used by the JGit command API.
Alternatively, make a working directory per web request. This is going
to be some really ugly code, so I wouldn't encourage it.