[jboss-user] [JBoss Cache Users] - Re: Null element in the Vector

roman.mandeleil@gmail.com do-not-reply at jboss.com
Mon Nov 23 02:35:11 EST 2009


Here is the output of simple concurrency test

Thread: [44] pushing
  | Thread: [45] poping
  | Thread: [45]
  | [null],
  | Thread: [45] poping
  | Thread: [44]
  | [23],
  | Thread: [44] pushing
  | Thread: [44]
  | [23], [23],
  | Thread: [45]
  | [null],
  | Thread: [44] pushing
  | Thread: [44]
  | [23], [23], [23],
  | Thread: [44] pushing
  | Thread: [44]
  | [23], [23], [23], [23],
  | Thread: [44] pushing
  | Thread: [44]
  | [23], [23], [23], [23], [23],
  | Thread: [44] pushing
  | Thread: [44]
  | [23], [23], [23], [23], [23], [23],
  | Thread: [45] poping
  | Thread: [44] pushing
  | Thread: [45]
  | [23], [23], [23], [23], [null],
  | Thread: [45] poping
  | Thread: [45]
  | [23], [23], [23], [null], [null], [23],
  | Thread: [45] poping
  | Thread: [44]
  | [null], [null], [null], [null], [null], [23], [23],
  | Thread: [44] pushing
  | Thread: [45]
  | [23], [23], [null], [null], [23], [null],
  | Thread: [45] poping
  | Thread: [45]
  | [23], [null], [null], [23], [null], [null], [23],




Here is the code of the test:



  | 
  | 
  | 
  | package org.galtstreet.cache.test;
  | 
  | import java.util.Properties;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.resource.NotSupportedException;
  | import javax.transaction.SystemException;
  | import javax.transaction.UserTransaction;
  | 
  | import junit.framework.TestCase;
  | 
  | import org.galtstreet.exchangeboard.trying.WrappedQueue;
  | import org.jboss.cache.config.Configuration.CacheMode;
  | import org.jboss.cache.factories.UnitTestConfigurationFactory;
  | import org.jboss.cache.lock.IsolationLevel;
  | import org.jboss.cache.pojo.PojoCache;
  | import org.jboss.cache.pojo.PojoCacheFactory;
  | 
  | 
  | public class SimpleConcurrencyTest extends TestCase{
  | 
  | 	
  | 	
  | 	   PojoCache cache1;
  | 	
  | 	protected void setUp() throws Exception {
  | 
  | 	      Properties prop = new Properties();
  | 	      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
  | 	      boolean toStart = false;
  | 	      
  | 	      
  | 	      
  | 	      cache1 = PojoCacheFactory.createCache(UnitTestConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
  | 	      cache1.getCache().getConfiguration().setSyncCommitPhase(true);
  | 
  | 	      cache1.getCache().getConfiguration().setLockParentForChildInsertRemove(true);
  | 	      cache1.getCache().getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
  | 	      cache1.start();
  | 	}
  | 
  | 	
  | 	UserTransaction getTransaction() throws SystemException, NotSupportedException, NamingException
  | 	{
  | 		Properties prop = new Properties();
  | 		prop.put(Context.INITIAL_CONTEXT_FACTORY,
  | 				"org.jboss.cache.transaction.DummyContextFactory");
  | 		return (UserTransaction) new InitialContext(prop).lookup("UserTransaction");
  | 	}	
  | 	
  | 	
  | 	public void testWrappedQueue(){
  | 		
  | 		WrappedQueue queue = new WrappedQueue();
  | 				
  | 		cache1.attach("queue-1", queue);
  | 
  | 		
  | 		ProducerThread pt = new ProducerThread(queue);
  | 		pt.start();
  | 		
  | 		
  | 		ConsumerThread ct = new ConsumerThread(queue);
  | 		ct.start();
  | 		
  | 		sleeping(120000);
  | 		
  | 	}
  | 	
  | 	
  | 	
  | 	class ConsumerThread extends Thread{
  | 		
  | 		WrappedQueue queue = null;
  | 		
  | 		public ConsumerThread(WrappedQueue queue) {
  | 			this.queue = queue;
  | 		}
  | 		
  | 		@Override
  | 		public void run() {
  | 			
  | 			while (true){
  | 				
  | 				UserTransaction ut = null;
  | 				
  | 				try {
  | 					ut = getTransaction();
  | 					ut.begin();
  | 				}catch (Throwable th){
  | 					th.printStackTrace();
  | 				}
  | 				
  | 				System.out.println("Thread: [" + this.getId() + "] poping ");
  | 				queue.popInteger();
  | 				
  | 				System.out.println("Thread: [" + this.getId() + "] \n" + queue.toString() );
  | 				sleeping(500);
  | 				
  | 
  | 				try {
  | 					ut.commit();
  | 				}catch (Throwable th){
  | 					th.printStackTrace();
  | 				}
  | 			}
  | 		}
  | 	}
  | 	
  | 	class ProducerThread extends Thread{
  | 		
  | 		WrappedQueue queue = null;
  | 		
  | 		public ProducerThread(WrappedQueue queue) {
  | 			this.queue = queue;
  | 		}
  | 		
  | 		@Override
  | 		public void run() {
  | 			
  | 			while (true){
  | 
  | 				UserTransaction ut = null;
  | 				
  | 				try {
  | 					ut = getTransaction();
  | 					ut.begin();
  | 				}catch (Throwable th){
  | 					th.printStackTrace();
  | 				}
  | 				
  | 				System.out.println("Thread: [" + this.getId() + "] pushing ");
  | 				queue.pushInteger(23);
  | 				System.out.println("Thread: [" + this.getId() + "] \n" + queue.toString() );
  | 				sleeping(100);
  | 
  | 				
  | 				try {
  | 					ut.commit();
  | 				}catch (Throwable th){
  | 					th.printStackTrace();
  | 				}
  | 				
  | 			}
  | 		}
  | 	}
  | 	
  | 	
  | 	private void sleeping(int millisec){
  | 		try {
  | 			Thread.sleep(millisec);
  | 		} catch (InterruptedException e) {
  | 			// TODO Auto-generated catch block
  | 			e.printStackTrace();
  | 		}
  | 	}
  | 	
  | 
  | 	protected void tearDown() throws Exception {
  | 		cache1.stop();
  | 		cache2.stop();
  | 
  | 	}
  | 
  | 		
  | 	
  | }
  | 
  | 
  | 


  | 
  | 
  | package org.galtstreet.exchangeboard.trying;
  | 
  | import java.util.ArrayList;
  | 
  | import org.jboss.cache.pojo.annotation.Replicable;
  | 
  | 
  | @Replicable
  | public class WrappedQueue {
  | 
  | 	
  | 	
  | 	private ArrayList<Integer> queueData = new ArrayList<Integer>();
  | 	
  | 	
  | 	public void pushInteger(Integer tmp){
  | 		queueData.add(queueData.size(), tmp);
  | 	}
  | 	
  | 	public Integer popInteger(){
  | 		return queueData.remove(0);
  | 	}
  | 	
  | 	public boolean isEmpty(){
  | 		return queueData.isEmpty();
  | 	}
  | 	
  | 	public String toString(){
  | 		return queueData.toString();
  | 	}
  | }
  | 
  | 

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

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



More information about the jboss-user mailing list