Spring 线程池使用
/**
*
*/
一个日志管理的类:
在批理更新,插入,等操作
package com.xiu.order.core.orders.impl;
import java.util.List;
import org.springframework.core.task.TaskExecutor;
import com.xiu.common.dao.persistence.exception.DAOException;
import com.xiu.order.core.exception.ManagerException;
import com.xiu.order.core.orders.LogManager;
import com.xiu.order.dal.orders.dao.LogDAO;
import com.xiu.order.dal.orders.dataobject.LogDO;
public class LogManagerImpl implements LogManager {
private LogDAO operatorLogDAO;
public LogDAO getOperatorLogDAO() {
return operatorLogDAO;
}
public void setOperatorLogDAO(LogDAO operatorLogDAO) {
this.operatorLogDAO = operatorLogDAO;
}
private TaskExecutor taskExecutor;
public void setTaskExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
@Override
public List<LogDO> queryOperatorLog(int orderId) throws ManagerException {
try {
return operatorLogDAO.queryOperatorLog(orderId);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
@Override
public int insertOperatorLog(LogDO operationLogDO) throws ManagerException {
try {
return operatorLogDAO.insertOperatorLog(operationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
@Override
public List<LogDO> queryOperatorLogList(LogDO operationLogDO)
throws ManagerException {
try {
return operatorLogDAO.queryOperatorLogList(operationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
public void batchAddOptLogAsync(final List<LogDO> optLogDOList)
throws ManagerException {
taskExecutor.execute(new Runnable() {
public void run() {
try {
operatorLogDAO.batchAddOptLogAsync(optLogDOList);
} catch (DAOException e) {
// System.out.println(e);
}
}
});
}
@Override
public void addOptLogAsync(final LogDO optLogDO) throws ManagerException {
taskExecutor.execute(new Runnable() {
public void run() {
try {
insertOperatorLog(optLogDO);
} catch (ManagerException e) {
e.printStackTrace();
}
}
});
}
@Override
public List<Integer> queryLogInfoByOrderIdListAndLogInfo(
List<Integer> orderIdList, LogDO oprationLogDO)
throws ManagerException {
try {
return operatorLogDAO.queryLogInfoByOrderIdListAndLogInfo(
orderIdList, oprationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
}
spring 配置
<bean id="operatorLogManager" class="com.xiu.order.core.orders.impl.LogManagerImpl ">
<property name="taskExecutor" ref="taskExecutor"></property>
</bean>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="30" />
</bean>
/**
*
*/
一个日志管理的类:
在批理更新,插入,等操作
package com.xiu.order.core.orders.impl;
import java.util.List;
import org.springframework.core.task.TaskExecutor;
import com.xiu.common.dao.persistence.exception.DAOException;
import com.xiu.order.core.exception.ManagerException;
import com.xiu.order.core.orders.LogManager;
import com.xiu.order.dal.orders.dao.LogDAO;
import com.xiu.order.dal.orders.dataobject.LogDO;
public class LogManagerImpl implements LogManager {
private LogDAO operatorLogDAO;
public LogDAO getOperatorLogDAO() {
return operatorLogDAO;
}
public void setOperatorLogDAO(LogDAO operatorLogDAO) {
this.operatorLogDAO = operatorLogDAO;
}
private TaskExecutor taskExecutor;
public void setTaskExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
@Override
public List<LogDO> queryOperatorLog(int orderId) throws ManagerException {
try {
return operatorLogDAO.queryOperatorLog(orderId);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
@Override
public int insertOperatorLog(LogDO operationLogDO) throws ManagerException {
try {
return operatorLogDAO.insertOperatorLog(operationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
@Override
public List<LogDO> queryOperatorLogList(LogDO operationLogDO)
throws ManagerException {
try {
return operatorLogDAO.queryOperatorLogList(operationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
public void batchAddOptLogAsync(final List<LogDO> optLogDOList)
throws ManagerException {
taskExecutor.execute(new Runnable() {
public void run() {
try {
operatorLogDAO.batchAddOptLogAsync(optLogDOList);
} catch (DAOException e) {
// System.out.println(e);
}
}
});
}
@Override
public void addOptLogAsync(final LogDO optLogDO) throws ManagerException {
taskExecutor.execute(new Runnable() {
public void run() {
try {
insertOperatorLog(optLogDO);
} catch (ManagerException e) {
e.printStackTrace();
}
}
});
}
@Override
public List<Integer> queryLogInfoByOrderIdListAndLogInfo(
List<Integer> orderIdList, LogDO oprationLogDO)
throws ManagerException {
try {
return operatorLogDAO.queryLogInfoByOrderIdListAndLogInfo(
orderIdList, oprationLogDO);
} catch (DAOException e) {
throw new ManagerException(e);
}
}
}
spring 配置
<bean id="operatorLogManager" class="com.xiu.order.core.orders.impl.LogManagerImpl ">
<property name="taskExecutor" ref="taskExecutor"></property>
</bean>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="30" />
</bean>