[jboss-user] [JBossCache] - Re: Threading Bug in PojoCache?

vincent.marquez do-not-reply at jboss.com
Wed May 2 21:35:45 EDT 2007


Hey Jason, thanks for taking time to respond to my earlier post.  To answer your questions, I'm not using Optimistic Locking, nor transactions. 

When I came back to investigating this bug, I wasn't able to replicate the exact exception, but there most definitely is a race condition and I have a test case to show it.  I'm not sure why I can't get the exact same exception, but I have a feeling they are directly related.  Do you have any ideas on why I'm getting in the original exception a "null pointer instance"?


To get the exception I can replicate with an easy test case, run the junit test after inserting a breakpoint in AdvisedPojoHandler at line 128.  

the line should be 

  |  util_.attachInterceptor(obj, advisor, interceptor, observer_);
  | 

Run the program, and at any time you wish to cause the exception, simply step over that line to the next one, and wait.  This is to simulate one thread reading the data at the exact time another thread could be inserting a pojo into the cache.  You shall see when the second thread attempts to access the pojo, an exception is thrown:


Exception in thread "READERTHREAD" org.jboss.cache.pojo.PojoCacheAlreadyDetachedException: pojo: class org.jboss.cache.pojo.test.Person has possibly been detached remotely. Internal id: /__JBossInternal__/personFqn/_ID_/a232u-oafb98-f18j8tg3-1-f18j8tgi-2
	at org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor.isPojoDetached(CacheFieldInterceptor.java:235)
	at org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor.invoke(CacheFieldInterceptor.java:179)
	at org.jboss.cache.pojo.test.JoinPoint_r_age_7.invokeNext(JoinPoint_r_age_7.java)
	at org.jboss.cache.pojo.test.JoinPoint_r_age_7.invokeJoinpoint(JoinPoint_r_age_7.java)
	at org.jboss.cache.pojo.test.Person$PersonAdvisor.Person$PersonAdvisor$age_r_$aop(Person$PersonAdvisor.java)
	at org.jboss.cache.pojo.test.Person$PersonInstanceAdvisor.Person$PersonAdvisor$age_r_$aop(Person$PersonInstanceAdvisor.java)
	at org.jboss.cache.pojo.test.Person.age_r_$aop(Person.java)
	at org.jboss.cache.pojo.test.Person.getAge(Person.java:76)
	at com.deltel.cache.test.ThreadTest$Reader.run(ThreadTest.java:69)
	at java.lang.Thread.run(Unknown Source)




My unit test I used to show the bug:

 
  | package com.deltel.cache.test;
  | 
  | import org.jboss.cache.config.Configuration;
  | import org.jboss.cache.config.Configuration.CacheMode;
  | import org.jboss.cache.pojo.test.Person;
  | import org.jboss.cache.lock.IsolationLevel;
  | import org.jboss.cache.pojo.PojoCache;
  | import org.jboss.cache.pojo.PojoCacheFactory;
  | 
  | import EDU.oswego.cs.dl.util.concurrent.Latch;
  | 
  | import junit.framework.Test;
  | import junit.framework.TestCase;
  | import junit.framework.TestSuite;
  | 
  | public class ThreadTest extends TestCase {
  | 	
  | 	protected PojoCache cache1;
  | 	
  | 	protected Person person = new Person();
  | 	 
  | 	protected String personFqn = "personFqn";
  | 	
  | 	private Latch finishedRead = new Latch();
  | 	
  | 	private Latch finishedAdd = new Latch();
  | 
  | 		public void setUp() throws Exception {
  | 		cache1 = this.fetchCache();
  | 		person.setAge(50);
  | 	}
  | 		
  | 	public void testRun() throws Exception {
  | 		
  | 		Thread t1 = new Thread(new Adder());
  | 		Thread t2 = new Thread(new Reader(),"READERTHREAD");
  | 		
  | 		t1.start();
  | 		t2.start();
  | 		
  | 		this.finishedAdd.acquire();
  | 		this.finishedRead.acquire();
  | 		
  | 		System.out.println("finished without an error");
  | 	}
  | 	
  | 	
  | 	public static Test suite() {
  | 		return new TestSuite(ThreadTest.class);
  |     }
  | 	
  | 		
  | 	private class Adder implements Runnable {
  | 		public void run() {
  | 			cache1.attach(personFqn, person);
  | 			finishedAdd.release();
  | 		}
  | 	}
  | 	
  | 	private class Reader implements Runnable {
  | 		public void run() {
  | 			for ( int x=0;x<50; x++ ) {
  | 				try {
  | 					Thread.sleep(10000);
  | 				} catch ( InterruptedException e ) {
  | 					
  | 				}
  | 				 
  | 				System.out.println("reading the field " + person.getAge());
  | 				 
  | 			}
  | 			finishedRead.release();
  | 		}
  | 	}
  | 	
  | 	PojoCache fetchCache() throws Exception { 
  | 		PojoCache cache = null;
  | 		Configuration config = new Configuration();
  | 		config.setCacheMode(CacheMode.REPL_SYNC);
  | 		config.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
  | 		config.setLockAcquisitionTimeout(100000);
  | 		config.setFetchInMemoryState(true);
  | 	 	config.setClusterName("test");
  | 		cache = PojoCacheFactory.createCache(config, false);
  | 		cache.start();
  | 		return cache;
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4042682#4042682

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4042682



More information about the jboss-user mailing list