标签:
数据库存储过程
drop PROCEDURE generate_serial_number; CREATE PROCEDURE generate_serial_number( IN param_key varchar(20), IN param_orgId int, OUT result int) begin START TRANSACTION; select number+1 into result from sys_serial_number where table_key=param_key and orgId = param_orgId for update; update sys_serial_number set number = number+1 where table_key=param_key and orgId = param_orgId; commit; end;
mybatis配置
<select id="generateSerialNumber" statementType="CALLABLE" parameterType="java.util.HashMap"> <![CDATA[ { call generate_serial_number ( #{param_key,mode=IN,jdbcType=VARCHAR}, #{param_orgId,mode=IN,jdbcType=BIGINT}, #{result,mode=OUT,jdbcType=VARCHAR} ) } ]]> </select>
测试代码
@Override public Map<String, Object> generateSerialNumber(Map<String, Object> param) { sysSerialNumberMapper.generateSerialNumber(param); return param; }
final Map<String, Object> param = new HashMap<String, Object>(); param.put("param_key","contract"); param.put("param_orgId", 84); new Thread(new Runnable() { @Override public void run() { for(int i =0; i<100; i++) { Map<String, Object> map = serialNumberProvider.generateSerialNumber(param); System.out.println("thread-1:" + map.get("result")); } } }).start(); new Thread(new Runnable() { @Override public void run() { for(int i =0; i<100; i++) { Map<String, Object> map = serialNumberProvider.generateSerialNumber(param); System.out.println("thread-2:" + map.get("result")); } } }).start(); new Thread(new Runnable() { @Override public void run() { for(int i =0; i<100; i++) { Map<String, Object> map = serialNumberProvider.generateSerialNumber(param); System.out.println("thread-3:" + map.get("result")); } } }).start(); byte[] b = new byte[0]; synchronized(b) { b.wait(); }
标签:
原文地址:http://www.cnblogs.com/cocoat/p/5808684.html