jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Walter Raboch <wrab...@ingen.at>
Subject Re: concurrency problem
Date Thu, 11 Aug 2005 14:29:07 GMT
Hi Stefan,

> the first InvalidItemStateException is correct. 
> i'll investigate the ItemNotFoundException. i guess there's 
> a 'synchronized' missing somewhere...

I extended my testcase a little bit. Now I lock the rootnode for 
adding/deleting subnodes. But the program hangs sometimes while
locking or releasing the lock again.

Some waitForLock() method would be cool too ;) Perhaps with
some sort of waitQueue. But I know - its not in the spec.

cheers,
Walter
--

public void run() {
		// simulate a user...
		debug("started.");
		String state = "";
		Lock l = null;
		Node rn = null;
		try {
			debug("1");
			rn = session.getRootNode();
			debug("2");
			int count = 0;
			while(rn.isLocked() && count < 30) {
				sleep();
				count++;
			}
			debug("3");
			l = rn.lock(false, true);
			debug("4");
	    	state = "searching testnode";
			if (rn.hasNode("testnode-" + identity)) {
				debug("4.1");
		    	try {
		    		state = "removing testnode";
		    		rn.getNode("testnode-" + identity).remove();
		    		debug("4.2");
		    		session.save();
			    	sleep();
		    	} catch(ItemNotFoundException infe) {
		    		debug("error while removing testnode " + identity);
		    		infe.printStackTrace();
		    	}
		    }
			debug("5");
     		state = "adding testnode";
		    Node n = rn.addNode("testnode-" + identity , "nt:unstructured");		
		    debug("6");
		    session.save();
		    debug("7");
		    rn.unlock();
		    debug("8");
		    state = "setting property";		
		    n.setProperty("testprop", new StringValue("Hello World!"));
		    session.save();
		    sleep();
		
		    for(int i=0; i<100; i++) {
		    	state = "adding subnode " + i;
		    	n.addNode("x" + i, "nt:unstructured");
		    	state = "adding property to subnode " + i;
		    	n.setProperty("testprop","xxx");
		    	if(i%10==0)	{
		    		state = "saving pending subnodes";
		    		session.save();
		    		System.out.print(".");
		    	}
		    	sleep();
		    }
		    session.save();

		} catch( Exception e) {
			debug("Exception: " + state);
			e.printStackTrace();
		} finally {
			if(l != null && rn != null) {
				try {
					rn.unlock();
				} catch( RepositoryException e ) {				
				}
			}
			session.logout();
		}

		debug("ended.");
	}

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message