jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Behrang Saeedzadeh" <behran...@gmail.com>
Subject Concurrent writing to a JCR repository
Date Sat, 30 Sep 2006 21:46:43 GMT
Hi,

I have written a very simple performance test for Jackrabbit that
creates 10 threads each saving 1000 simple one-property nodes to the
repository.

When I run the test, an exception is thrown:

javax.jcr.ItemNotFoundException:
0cada011-dc27-4531-bfcc-e8dde67532d9/{http://www.jcp.org/jcr/1.0}primaryType
	at org.apache.jackrabbit.core.ItemManager.createItemInstance(ItemManager.java:464)
	at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:320)
	at org.apache.jackrabbit.core.ItemImpl.restoreTransientItems(ItemImpl.java:708)
	at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1208)
	at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:805)



When I reduce the thread count to 1, the program completes with no
problem so the problem should be that I am using the JCR API
incorrectly. Could someone please show me how can I fix the sample
program so that it works correctly?

Regards,
Behi

The Code:

--- --- --- ---
/*
 * Created by Behrang Saeedzadeh
 *  on Sep 29, 2006 @ 5:30:34 PM
 */
package org.behrang.practice.jsr170;

import org.apache.jackrabbit.core.TransientRepository;

import javax.jcr.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Behrang Saeedzadeh
 */
public class Main {

    public static void main(String[] args) throws Exception {

        final int THREAD_COUNT = 10;

        Repository rep = new TransientRepository();
        List<Session> sessions = new ArrayList<Session>(THREAD_COUNT);

        Session s = rep.login(new SimpleCredentials("username",
"password".toCharArray()));
        s.getRootNode().addNode("positions").remove();
        s.getRootNode().addNode("positions");
        s.save();
        s.logout();

        for (int i = 0; i < THREAD_COUNT; i++) {
            Session sess = rep.login(new SimpleCredentials("User " +
(i + 1), "password".toCharArray()));
            sessions.add(sess);
        }

        for (Session sess : sessions) {
            new Thread(new UserThread(sess)).start();
        }

    }

}

class UserThread implements Runnable {

    private Session session;
    private long start;
    private long end;
    private String user;

    public UserThread(Session session) {
        this.session = session;
        this.user = session.getUserID();
    }

    public void run() {
        start = System.currentTimeMillis();
        try {
            for (int i = 0; i < 100; i++) {
                Node root = session.getRootNode();
                Node positions = root.getNode("positions");
                Node position = positions.addNode("position");
                position.setProperty("name", user + " " + (i + 1));
            }

            session.save();
            session.logout();
            end = System.currentTimeMillis();
            synchronized(System.out) {
                System.out.println(user + " finished its job at " +
(end - start) / 1000d);
            }
        } catch (RepositoryException re) {
            re.printStackTrace();
        }
    }
}
--- --- --- ---

-- 
"Science is a differential equation. Religion
is a boundary condition" - Alan Turing

Behrang Saeedzadeh
http://www.jroller.com/page/behrangsa
http://my.opera.com/behrangsa

Mime
View raw message