2013-06-22 104 views
0

在我目前的Tomcat项目中,我整合了JackRabbit。其功能运作良好。但是,存储库的启动非常缓慢。花了大约5秒。我认为这是无法忍受的。任何人都有关于如何将Jackrabbit集成到Web项目的一些想法?jackrabbit start repository slow

目前,我在Web项目中拥有自己的Session工厂。代码如下:

public class TMPSessionFactory { 
    public static Session getSession() throws RepositoryException, NamingException { 
    String configFile = "C:\\workspaces\\repository.xml"; 
    String repHomeDir = "C:\\JackRabbitDemo\\repository"; 
    Hashtable<String, Object> hashTable = new Hashtable<String, Object>(); 
    hashTable.put(Context.INITIAL_CONTEXT_FACTORY, DummyInitialContextFactory.class.getName()); 
    hashTable.put(Context.PROVIDER_URL, "127.0.0.1"); 
    InitialContext ctx = new InitialContext(hashTable); 
    RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true); 
    Repository r = (Repository) ctx.lookup("repo"); 

    SimpleCredentials cred = new SimpleCredentials("admin", "admin".toCharArray()); 
    Session session = r.login(cred, null); 

    return session;}} 

每次如果我需要一个jackrabbit会话,我会调用这个静态函数。

我不知道我的方式是否合适,因为它的工作原理,但不够好(每次存储库的启动都很慢)。

回答

0

您是否指您在每次访问存储库时查看每个存储库之前创建一个新存储库并将其绑定到JNDI? 全部代码:

String configFile = "C:\\workspaces\\repository.xml"; 
String repHomeDir = "C:\\JackRabbitDemo\\repository"; 
Hashtable<String, Object> hashTable = new Hashtable<String, Object>(); 
hashTable.put(Context.INITIAL_CONTEXT_FACTORY, DummyInitialContextFactory.class.getName()); 
hashTable.put(Context.PROVIDER_URL, "127.0.0.1"); 
InitialContext ctx = new InitialContext(hashTable); 
RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true); 

应该只调用一次。 也许您应该将您的jackrabbit存储库声明为Tomcat资源,因为它记录在此处:https://jackrabbit.apache.org/shared-j2ee-resource-howto.html

+0

感谢您的回答。问题是我现在正在使用Tomcat 7。我尝试过类似于之前文档所述的配置,但它似乎不起作用。你有这个想法吗? – cjmemory