|Re: [jgit-dev] JGit thread safety|
On Thu, Apr 18, 2013 at 4:26 AM, Dimitar Georgiev <dimitar.georgiev.bg@xxxxxxxxx> wrote: > 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 only one. > 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 / > checkout? 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.
Back to the top