我试图使用不同的线程,使用SVNKit并行地连接到许多SVN存储库。
查看一些在线代码示例,在使用SVNKit之前,我必须使用静态方法初始化它。
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();显然,静态方法使我在多线程环境中感到担忧。我的问题是:
如果有人能解释我为什么要这样称呼这些方法,我也会很高兴。
发布于 2010-09-16 22:06:36
在不同的线程中创建存储库实例之前,只需调用一次此方法。
来自SVNRepositoryFactoryImpl javadoc:
在使用库之前,
只在应用程序中执行一次,就可以通过svn协议(通过svn和svn+ssh)使用存储库。
下面是一个包含2个存储库(单线程)的示例代码:
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));在多线程环境中,您可以创建一个实现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
}
}像这样使用它:
SVNRepositoryFactoryImpl.setup(); // STILL ONCE!
(new Thread(new ProcessSVN("http://svnurl1"))).start();
(new Thread(new ProcessSVN("http://svnurl2"))).start();https://stackoverflow.com/questions/3702778
复制相似问题