I'm trying to connect to many SVN repositories in parallel, using different threads, with SVNKit.
Looking at some code examples online, it looks like before using SVNKit I have to initialize it using the static methods
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
Obviously static methods make me concerned in a multithreaded environment. My question is:
I would also be glad if someone could explain the reason I have to call these methods.
You only have to call this method once, before creating repository instances in your different threads.
From SVNRepositoryFactoryImpl javadoc:
do it once in your application prior to using the library enables working with a repository via the svn-protocol (over svn and svn+ssh)
Here is an example code with 2 repositories (monothread) :
SVNRepositoryFactoryImpl.setup(); // ONCE!
String url1 = "svn://host1/path1";
SVNRepository repository1 = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url1));
String url2 = "svn://host2/path2";
SVNRepository repository2 = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url2));
In multithread environment, you can create a class implementing Runnable:
public class ProcessSVN implements Runnable {
private String url;
public ProcessSVN(String url) {
this.url = url;
}
public void run() {
SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
// do stuff with repository
}
}
And use it like this:
SVNRepositoryFactoryImpl.setup(); // STILL ONCE!
(new Thread(new ProcessSVN("http://svnurl1"))).start();
(new Thread(new ProcessSVN("http://svnurl2"))).start();