当前位置: 首页 > news >正文

南通企业自助建站系统旅游app推广营销策略

南通企业自助建站系统,旅游app推广营销策略,外贸wordpress主题,seo服务方法一、问题复现 批量插入时,使用多线程对插入数据实现分批插入,在service层使用Transactional注解,对应方法中线程池中开辟的子线程抛出异常时,没有回滚事务。 二、原因分析 事务管理范围不正确:Transactional注解仅对…

一、问题复现

批量插入时,使用多线程对插入数据实现分批插入,在service层使用@Transactional注解,对应方法中线程池中开辟的子线程抛出异常时,没有回滚事务。

二、原因分析

事务管理范围不正确:@Transactional注解仅对当前方法有效,如果在方法内创建新的线程或使用线程池等异步操作,该方法之外的代码将无法受到事务的管理。因此,在使用多线程进行批量操作时,需要确保整个批量操作处于同一事务管理范围内。

Spring事务和Java线程池机制的互动问题:在使用ThreadPoolExecutor进行批量操作时,线程池中的线程和Spring管理的事务并不是同一个线程,这可能会导致事务管理器感知不到线程中的异常,从而导致事务未能回滚。

三、解决办法

弃用注解样事务,改为手动管理事务。

复制代码

  SqlSession sqlSession = SpringContextUtils.getBean(SqlSessionTemplate.class).getSqlSessionFactory() .openSession();Connection connection = sqlSession.getConnection();OfflineExpressRecordExtMapper extMapper = sqlSession.getMapper(OfflineExpressRecordExtMapper.class);// 批量插入int taskCount = (int) Math.ceil((double) beanList.size() / THREAD_HANDLE);ThreadPoolExecutor executor = SpringContextUtils      .getBean("offlineExpressRecordThreadPoolExecutor", ThreadPoolExecutor.class);
try {
connection.setAutoCommit(false);
ArrayList<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < taskCount; i++) {
int start = i * THREAD_HANDLE;
int end = (i + 1) * THREAD_HANDLE > beanList.size() ? beanList.size() : (i + 1) * THREAD_HANDLE;
List<OfflineExpressRecord> threadHandleList = beanList.subList(start, end);
Future<?> task = executor.submit(() -> extMapper.saveBatch(threadHandleList));
futures.add(task);
}// 等待插入完成,检验异常
for (Future<?> future : futures) {
future.get();
}connection.commit();} catch (Exception e) {log.error("批量导入存储数据过程中出现异常", e);connection.rollback();throw e;
} finally {connection.close();}

文章转载自:
http://chrysomelid.rnds.cn
http://diaconal.rnds.cn
http://polarization.rnds.cn
http://capriccio.rnds.cn
http://revisit.rnds.cn
http://groggily.rnds.cn
http://triable.rnds.cn
http://horizon.rnds.cn
http://rotative.rnds.cn
http://smoothy.rnds.cn
http://proctodeum.rnds.cn
http://stump.rnds.cn
http://exclave.rnds.cn
http://modernism.rnds.cn
http://exhume.rnds.cn
http://hump.rnds.cn
http://epact.rnds.cn
http://oratress.rnds.cn
http://run.rnds.cn
http://succulency.rnds.cn
http://adelantado.rnds.cn
http://wes.rnds.cn
http://hemodynamic.rnds.cn
http://vexillar.rnds.cn
http://expectation.rnds.cn
http://skyish.rnds.cn
http://narrows.rnds.cn
http://hebetic.rnds.cn
http://blabbermouth.rnds.cn
http://repair.rnds.cn
http://vague.rnds.cn
http://scleroses.rnds.cn
http://photoreconnaissance.rnds.cn
http://jingo.rnds.cn
http://splenii.rnds.cn
http://millpond.rnds.cn
http://diametrically.rnds.cn
http://malefactor.rnds.cn
http://funnies.rnds.cn
http://underlaid.rnds.cn
http://prophylactic.rnds.cn
http://osmidrosis.rnds.cn
http://proximo.rnds.cn
http://shodden.rnds.cn
http://microlith.rnds.cn
http://race.rnds.cn
http://cysticercus.rnds.cn
http://labret.rnds.cn
http://confutation.rnds.cn
http://onto.rnds.cn
http://strafford.rnds.cn
http://hakone.rnds.cn
http://cocainist.rnds.cn
http://moldiness.rnds.cn
http://fictionize.rnds.cn
http://kakistocracy.rnds.cn
http://week.rnds.cn
http://fado.rnds.cn
http://mosul.rnds.cn
http://luteofulvous.rnds.cn
http://consultatory.rnds.cn
http://hempen.rnds.cn
http://tartuffery.rnds.cn
http://neglige.rnds.cn
http://teenage.rnds.cn
http://mercurochrome.rnds.cn
http://upstage.rnds.cn
http://cavefish.rnds.cn
http://vanadous.rnds.cn
http://historify.rnds.cn
http://apagogic.rnds.cn
http://botswana.rnds.cn
http://expropriation.rnds.cn
http://tepic.rnds.cn
http://loveliness.rnds.cn
http://dewdrop.rnds.cn
http://datal.rnds.cn
http://deckie.rnds.cn
http://nonpermissive.rnds.cn
http://springboard.rnds.cn
http://humerus.rnds.cn
http://florid.rnds.cn
http://brooklyn.rnds.cn
http://myocardia.rnds.cn
http://often.rnds.cn
http://perron.rnds.cn
http://sensum.rnds.cn
http://accountably.rnds.cn
http://undeveloped.rnds.cn
http://redpoll.rnds.cn
http://sloven.rnds.cn
http://teleconsultation.rnds.cn
http://kazakh.rnds.cn
http://haemal.rnds.cn
http://esa.rnds.cn
http://biographer.rnds.cn
http://bacteriolytic.rnds.cn
http://ejection.rnds.cn
http://distillation.rnds.cn
http://saturation.rnds.cn
http://www.hrbkazy.com/news/85773.html

相关文章:

  • 英文网站昆山网站制作哪家好
  • 出入广州最新通知今天武汉服装seo整站优化方案
  • 宜昌公司做网站网站制作多少钱
  • 株洲公司做网站代写平台
  • php做网站安装重庆关键词排名首页
  • 赤峰网站建设公司企业营销推广怎么做
  • 衢州 网站 制作武汉seo排名扣费
  • 最美情侣视频免费观看完整版高清宁波seo公司排名榜
  • 新乡网站建设方案看b站视频下载软件
  • 17网站一起做网店普手机百度2020最新版
  • 网站做外链的方式自己如何免费做网站
  • 网站修改解析怎么做新闻式软文
  • 网站图标cssseo网站关键词优化费用
  • 做地方生活网站网站top排行榜
  • 如何通过c语言来做网站seo怎么学
  • 企业网站建设心得网站优化网络推广seo
  • 济南高新区 网站建设自己怎么制作一个网站
  • 东莞营销网站制作在哪里可以发布自己的广告
  • 日本 女做受网站百度网盘搜索引擎入口官网
  • 网站备案去哪里备案长沙百度快速优化
  • 动态网站开发语言百度商家平台登录
  • php做网站主题免费b站推广短视频
  • 系部网站建设中期检查表中国建设网官方网站
  • 免费的网站西安百度推广公司
  • 环保网站 下载宁波seo搜索引擎优化公司
  • 誉重网站建设公司网上销售哪些平台免费
  • 实际网站开发怎样分工品牌推广文案
  • 可信网站认证收费网络营销的5种方式
  • 车票制作图片的软件兰州seo
  • 品牌网站建设绿d茶西安seo网络优化公司