<aop:config>
<aop:aspect id="nIntercepter" ref="loginCheckAspect">
<aop:around pointcut="execution(* *..*ServiceImpl.*(..)) )"
method="serviceIntercept" />
</aop:aspect>
</aop:config>
public abstract class BaseService {
public BaseService()
{
}
public abstract String getPmId();
public abstract void ResetG();
}
public class LoginCheckInterceptor
implements Ordered
{
public LoginCheckInterceptor()
{
}
public void serviceIntercept(ProceedingJoinPoint pjp)
throws Throwable
{
BaseService baseService = (BaseService)pjp.getTarget();
baseService.ResetG();
}
public int getOrder()
{
return order;
}
public void setOrder(int order)
{
this.order = order;
}
private int order;
}
Friday, August 15, 2014
Multithreading and Transaction
Every thread have common value of operation like what type of operation to go Or standard protocal when to commit ,when to rollback,how many transaction object to create so it is set once and use by all thread .
Whether every thread share same object,Or for everythread the object is different.If they share it will be singleton and need sychronization .
Creating a common scenario of data for db operation for all thread by setting as singleton
there are lost of set method in a class in DataSourceTransactionManager.So,need to make sure what is common protocal for all threads
Whether every thread share same object,Or for everythread the object is different.If they share it will be singleton and need sychronization .
Creating a common scenario of data for db operation for all thread by setting as singleton
there are lost of set method in a class in DataSourceTransactionManager.So,need to make sure what is common protocal for all threads
Mocking Dao
package org.apache.tomcat.jdbc.pool.jmx;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class MockCommonDao extends SqlMapClientDaoSupport {
ArrayList<ArrayList> listOlists = new ArrayList<ArrayList>();
public List selectByExample(List<Object> example)
{
List<Future<Object>> listOlists = null;
ExecutorService executor = Executors.newFixedThreadPool(example.size());
List<TransactionImpl> callingList = new ArrayList<MockCommonDao.TransactionImpl>();
for (int i = 0; i < example.size(); i++) {
TransactionImpl localImpl = new TransactionImpl(example.get(i));
callingList.add(localImpl);
}
try {
listOlists = executor.invokeAll(callingList);
} catch (InterruptedException e) {
}
return listOlists;
}
private String getClassNameFromExample(Object example)
{
String tableName = example.getClass().getName();
int cnt = tableName.indexOf("Example");
int last = tableName.lastIndexOf('.');
tableName = tableName.substring(last + 1, cnt);
return tableName.toUpperCase();
}
private class TransactionImpl implements Callable<Object>{
private Object example;
TransactionImpl(Object Criteria) {
this.example = Criteria;
}
@Override
public Object call() throws Exception {
List list = getSqlMapClientTemplate().queryForList((new StringBuilder(String.valueOf(getClassNameFromExample(example)))).append(".ibatorgenerated_selectByExample").toString(), example);
listOlists.add((ArrayList) list);
return listOlists;
}
}}
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class MockCommonDao extends SqlMapClientDaoSupport {
ArrayList<ArrayList> listOlists = new ArrayList<ArrayList>();
public List selectByExample(List<Object> example)
{
List<Future<Object>> listOlists = null;
ExecutorService executor = Executors.newFixedThreadPool(example.size());
List<TransactionImpl> callingList = new ArrayList<MockCommonDao.TransactionImpl>();
for (int i = 0; i < example.size(); i++) {
TransactionImpl localImpl = new TransactionImpl(example.get(i));
callingList.add(localImpl);
}
try {
listOlists = executor.invokeAll(callingList);
} catch (InterruptedException e) {
}
return listOlists;
}
private String getClassNameFromExample(Object example)
{
String tableName = example.getClass().getName();
int cnt = tableName.indexOf("Example");
int last = tableName.lastIndexOf('.');
tableName = tableName.substring(last + 1, cnt);
return tableName.toUpperCase();
}
private class TransactionImpl implements Callable<Object>{
private Object example;
TransactionImpl(Object Criteria) {
this.example = Criteria;
}
@Override
public Object call() throws Exception {
List list = getSqlMapClientTemplate().queryForList((new StringBuilder(String.valueOf(getClassNameFromExample(example)))).append(".ibatorgenerated_selectByExample").toString(), example);
listOlists.add((ArrayList) list);
return listOlists;
}
}}
Subscribe to:
Posts (Atom)