来自热心网友的测试和思考

This commit is contained in:
小柒2012
2018-05-20 19:16:19 +08:00
parent dbed8babaa
commit e0af08b8e2
2 changed files with 3 additions and 1 deletions

View File

@@ -84,6 +84,8 @@ public class SeckillServiceImpl implements ISeckillService {
try {
lock.lock();
//这里、不清楚为啥、总是会被超卖101、难道锁不起作用、lock是同一个对象
//来自热心网友 zoain 的细心测试思考、然后自己总结了一下
//事物未提交之前,锁已经释放(事物提交是在整个方法执行完),导致另一个事物读取到了这个事物未提交的数据,也就是传说中的脏读。建议锁上移
String nativeSql = "SELECT number FROM seckill WHERE seckill_id=?";
Object object = dynamicQuery.nativeQueryObject(nativeSql, new Object[]{seckillId});
Long number = ((Number) object).longValue();

View File

@@ -25,7 +25,7 @@ public class SeckillController {
private final static Logger LOGGER = LoggerFactory.getLogger(SeckillController.class);
private static int corePoolSize = Runtime.getRuntime().availableProcessors();
//调整队列数 拒绝服务
//创建线程池 调整队列数 拒绝服务
private static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, corePoolSize+1, 10l, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(1000));