Exception when I use multithreading while pojocache.attach()
mhatreakshay Aug 4, 2008 3:46 AMI am trying to attach an object to a pojo cache using multi threading.But it throws an concurrent access exception.Below is the code snippet and the exception.Please suggest.
eg:
running the below code in a for loop
CacheWithThreadPoolExecutor.pool.execute(new CacheWithThreadPoolExecutor(COUNTERPARTYINFO+clientName+FUNDCPTYMAP ,fundNamesCpty));
public class CacheWithThreadPoolExecutor implements Runnable{
private String path;
private Object object;
private PojoCache cache = WSPojoCacheImpl.getInstance().getCache();
public static ThreadPoolExecutor pool;
static
{
pool = new ThreadPoolExecutor(10, 50, 60, TimeUnit.SECONDS,new ArrayBlockingQueue(10));
// pool.execute(new CacheWithThreadPoolExecutor());
}
public CacheWithThreadPoolExecutor(String path,Object object)
{
this.path = path;
this.object = object;
}
@Override
public void run() {
cache.attach(path, object);
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
}
==============================================
Exception
==============================================
10:43:26,928 WARN [PojoTxInterceptor] attach: exception occurred: java.util.ConcurrentModificationException
10:43:26,928 INFO [PojoTxInterceptor] endTransaction(): rolling back tx for id: /WS/COUNTERPARTYINFO/FUNDCPTYMAP
10:43:26,935 ERROR [STDERR] Exception in thread "pool-1-thread-1"
10:43:26,937 ERROR [STDERR] org.jboss.cache.pojo.PojoCacheException: PojoCache operation will be rollback. id: /WS/COUNTERPARTYINFO/FUNDCPTYMAP. Operation: attach
10:43:26,937 ERROR [STDERR] at org.jboss.cache.pojo.interceptors.PojoTxInterceptor.invoke(PojoTxInterceptor.java:91)
10:43:26,937 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
10:43:26,937 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl$attach_3085019539260813833.invokeNext(PojoCacheImpl$attach_3085019539260813833.java)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.interceptors.CheckNonSerializableInterceptor.invoke(CheckNonSerializableInterceptor.java:46)
10:43:26,938 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl$attach_3085019539260813833.invokeNext(PojoCacheImpl$attach_3085019539260813833.java)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.interceptors.CheckIdInterceptor.invoke(CheckIdInterceptor.java:33)
10:43:26,938 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl$attach_3085019539260813833.invokeNext(PojoCacheImpl$attach_3085019539260813833.java)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.interceptors.PojoBeginInterceptor.invoke(PojoBeginInterceptor.java:36)
10:43:26,938 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl$attach_3085019539260813833.invokeNext(PojoCacheImpl$attach_3085019539260813833.java)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl.attach(PojoCacheImpl.java)
10:43:26,938 ERROR [STDERR] at org.jboss.cache.pojo.impl.PojoCacheImpl.attach(PojoCacheImpl.java:93)
10:43:26,939 ERROR [STDERR] at com.globeop.webservice_metro.server.cache.CacheWithThreadPoolExecutor.run(CacheWithThreadPoolExecutor.java:31)
10:43:26,939 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
10:43:26,939 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
10:43:26,939 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)