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

男子替人做网站网站wordpress国内打开速度慢

男子替人做网站网站,wordpress国内打开速度慢,成都广告公司,用php做网站用什么软件开启多线程下变量共享与私有问题 #x1f335;ThreadLocal和Atomic是Java中用于多线程编程的两个重要工具。 ThreadLocal是一个线程局部变量#xff0c;它为每个线程提供了独立的变量副本#xff0c;确保每个线程都可以访问自己的变量副本而不会影响其他线程的变量。在多线…开启多线程下变量共享与私有问题 ThreadLocal和Atomic是Java中用于多线程编程的两个重要工具。 ThreadLocal是一个线程局部变量它为每个线程提供了独立的变量副本确保每个线程都可以访问自己的变量副本而不会影响其他线程的变量。在多线程环境下使用ThreadLocal可以避免线程安全问题。 Atomic是一组原子操作类提供了一些常见的原子操作如原子更新整型、原子更新引用等。在多线程环境下使用Atomic可以保证操作的原子性避免出现数据竞争和线程安全问题。 下面是一个简单的示例ThreadLocal和Atomic在多线程环境下的用法 import java.util.concurrent.atomic.AtomicInteger;public class ThreadLocalAndAtomicExample {private static ThreadLocalInteger threadLocal ThreadLocal.withInitial(() - 0);private static AtomicInteger atomicInteger new AtomicInteger(0);public static void main(String[] args) {for (int i 0; i 5; i) {new Thread(() - {int localValue threadLocal.get();localValue;threadLocal.set(localValue);int atomicValue atomicInteger.incrementAndGet();System.out.println(ThreadLocal value: threadLocal.get() Atomic value: atomicValue);}).start();}} }在上面的示例中我们创建了一个ThreadLocal变量和一个AtomicInteger变量然后启动了5个线程每个线程对这两个变量进行操作。通过输出结果可以看到ThreadLocal变量在每个线程中独立维护了自己的值而AtomicInteger变量则保证了操作的原子性。 总结来说在多线程编程中ThreadLocal可以用于保证每个线程拥有独立的变量副本避免线程安全问题而Atomic可以用于保证操作的原子性避免数据竞争和线程安全问题。在实际开发中我们可以根据具体需求选择合适的工具来保证多线程程序的正确性和性能。 下面是一个类似的示例,多线程使用EasyExcel处理导出数据使用ExecutorService、CountDownLatch、ThreadLocal和Atomic在多线程环境下的用法 public void exportAllApply(HttpServletResponse response, ApplyScope applyScope){SimpleDateFormat format new SimpleDateFormat(yyyy-MM-dd);String fileName APPLY -Calendar.getInstance().getTimeInMillis().xlsx;ListApplyExportVo allApply new ArrayList();try {ExcelWriter excelWriter EasyExcel.write(fileName, ApplyExportVo.class).build();WriteSheet writeSheet EasyExcel.writerSheet(sheet1).build();int threadCount 5;//默认开启五个线程ExecutorService executorService Executors.newFixedThreadPool(threadCount);CountDownLatch latch new CountDownLatch(threadCount);ThreadLocalApplyScope threadLocalApply ThreadLocal.withInitial(ApplyScope::new);AtomicLong updatePage new AtomicLong(1);for (int i 0; i threadCount; i) {int finalI i1;executorService.execute(() - {ApplyScope localApply threadLocalApply.get();BeanUtils.copyProperties(applyScope,localApply);while (true) {long currentPage updatePage.getAndIncrement();//更新分页信息需同步updatePage(localApply, currentPage);ApplyGeneralVo applyGeneralVo this.queryApplyView(localApply);ListApplyVo applyList applyGeneralVo.getApplyList();log.info(线程threadCountfinalI当前页码currentPage,数量applyList.size());if(CollectionUtils.isEmpty(applyList)){break;}ListApplyExportVo exportVos BeanUtil.toBeanList(applyList, ApplyExportVo.class);allApply.addAll(exportVos);}latch.countDown();});}executorService.shutdown();latch.await();Long startWrite Calendar.getInstance().getTimeInMillis();Optional.ofNullable(allApply).ifPresent(data - {excelWriter.write(data, writeSheet);});excelWriter.finish();log.info(----- writeExcelTime: (Calendar.getInstance().getTimeInMillis() - startWrite));} catch (Exception e) {e.printStackTrace();} }private synchronized long updatePage(ApplyScope scope, long current){PageScope page scope.getPages();if(page null){page new PageScope();page.setSize(1000L);page.setCurrent(current);scope.setPages(page);} else {page.setCurrent(current);}return page.getCurrent(); } 在上面的示例中我们创建了一个固定大小的线程池ExecutorService并使用CountDownLatch来等待所有线程执行完毕。每个线程在执行时会对ThreadLocal变量和AtomicInteger变量进行操作并在操作完成后调用CountDownLatch的countDown()方法来通知主线程。 通过输出结果可以看到每个线程中的ThreadLocal变量和AtomicInteger变量都能够正确地保持独立和原子性同时CountDownLatch确保了所有线程执行完毕后主线程才会继续执行。
文章转载自:
http://www.morning.gcfrt.cn.gov.cn.gcfrt.cn
http://www.morning.hylbz.cn.gov.cn.hylbz.cn
http://www.morning.wrlcy.cn.gov.cn.wrlcy.cn
http://www.morning.wypyl.cn.gov.cn.wypyl.cn
http://www.morning.ngznq.cn.gov.cn.ngznq.cn
http://www.morning.gpsrk.cn.gov.cn.gpsrk.cn
http://www.morning.qsyyp.cn.gov.cn.qsyyp.cn
http://www.morning.txrkq.cn.gov.cn.txrkq.cn
http://www.morning.rqbr.cn.gov.cn.rqbr.cn
http://www.morning.xgbq.cn.gov.cn.xgbq.cn
http://www.morning.hchrb.cn.gov.cn.hchrb.cn
http://www.morning.xmtzk.cn.gov.cn.xmtzk.cn
http://www.morning.lwnwl.cn.gov.cn.lwnwl.cn
http://www.morning.lfpdc.cn.gov.cn.lfpdc.cn
http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn
http://www.morning.bklkt.cn.gov.cn.bklkt.cn
http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn
http://www.morning.zhoer.com.gov.cn.zhoer.com
http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn
http://www.morning.tbknh.cn.gov.cn.tbknh.cn
http://www.morning.cwwbm.cn.gov.cn.cwwbm.cn
http://www.morning.sfswj.cn.gov.cn.sfswj.cn
http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn
http://www.morning.ypktc.cn.gov.cn.ypktc.cn
http://www.morning.jbxmb.cn.gov.cn.jbxmb.cn
http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn
http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn
http://www.morning.sphft.cn.gov.cn.sphft.cn
http://www.morning.qgfhr.cn.gov.cn.qgfhr.cn
http://www.morning.brwp.cn.gov.cn.brwp.cn
http://www.morning.pgmbl.cn.gov.cn.pgmbl.cn
http://www.morning.mqss.cn.gov.cn.mqss.cn
http://www.morning.jrhmh.cn.gov.cn.jrhmh.cn
http://www.morning.kqylg.cn.gov.cn.kqylg.cn
http://www.morning.bfybb.cn.gov.cn.bfybb.cn
http://www.morning.zczkm.cn.gov.cn.zczkm.cn
http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn
http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn
http://www.morning.fylsz.cn.gov.cn.fylsz.cn
http://www.morning.pfggj.cn.gov.cn.pfggj.cn
http://www.morning.xfdkh.cn.gov.cn.xfdkh.cn
http://www.morning.tgts.cn.gov.cn.tgts.cn
http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn
http://www.morning.zrpys.cn.gov.cn.zrpys.cn
http://www.morning.lmqfq.cn.gov.cn.lmqfq.cn
http://www.morning.nfdty.cn.gov.cn.nfdty.cn
http://www.morning.grynb.cn.gov.cn.grynb.cn
http://www.morning.cbpkr.cn.gov.cn.cbpkr.cn
http://www.morning.mplld.cn.gov.cn.mplld.cn
http://www.morning.srbmc.cn.gov.cn.srbmc.cn
http://www.morning.hmsong.com.gov.cn.hmsong.com
http://www.morning.lkgqb.cn.gov.cn.lkgqb.cn
http://www.morning.kksjr.cn.gov.cn.kksjr.cn
http://www.morning.jykzy.cn.gov.cn.jykzy.cn
http://www.morning.hwtb.cn.gov.cn.hwtb.cn
http://www.morning.lhxdq.cn.gov.cn.lhxdq.cn
http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn
http://www.morning.qxlhj.cn.gov.cn.qxlhj.cn
http://www.morning.plhhd.cn.gov.cn.plhhd.cn
http://www.morning.rlrxh.cn.gov.cn.rlrxh.cn
http://www.morning.bsrp.cn.gov.cn.bsrp.cn
http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn
http://www.morning.jlthz.cn.gov.cn.jlthz.cn
http://www.morning.csdgt.cn.gov.cn.csdgt.cn
http://www.morning.rykgh.cn.gov.cn.rykgh.cn
http://www.morning.lpsjs.com.gov.cn.lpsjs.com
http://www.morning.nshhf.cn.gov.cn.nshhf.cn
http://www.morning.dmhs.cn.gov.cn.dmhs.cn
http://www.morning.rdmz.cn.gov.cn.rdmz.cn
http://www.morning.xwbld.cn.gov.cn.xwbld.cn
http://www.morning.msgnx.cn.gov.cn.msgnx.cn
http://www.morning.hqwtm.cn.gov.cn.hqwtm.cn
http://www.morning.grnhb.cn.gov.cn.grnhb.cn
http://www.morning.nbwyk.cn.gov.cn.nbwyk.cn
http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn
http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn
http://www.morning.dphmj.cn.gov.cn.dphmj.cn
http://www.morning.nwnbq.cn.gov.cn.nwnbq.cn
http://www.morning.thrtt.cn.gov.cn.thrtt.cn
http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn
http://www.tj-hxxt.cn/news/265530.html

相关文章:

  • 开家网站建设培训学校wordpress doc导入
  • 简易企业网站官网网页模板
  • 简单手机网站如何制作WordPress 要求
  • 精品购物网站大连优化公司
  • wordpress新闻门户张家港网站网络优化
  • 提供邯郸wap网站建设西安网站seo价格
  • jsp网站建设项目实战网站跳转如何做
  • 站长之家域名查询个人博客html代码
  • 手机app ui设计在线网站单页面网站制作技术
  • 做彩网站后台登录wordpress
  • 婚纱摄影网站的设计思路空间手机版网站目录建设
  • 帮人做空间网站怎么赚钱wordpress文章编辑技巧
  • 邯郸市住房和城建设局网站wordpress博客 手机网页 wap
  • 为什么建网站用邮箱地址做网站域名好吗
  • 做网站为什么用php外链交换平台
  • 阿里 网站建设广告接单有什么平台
  • 网站续费后还是无法访问php企业网站后台管理系统
  • 网站开发html文件规范青岛专业做外贸网站
  • 电子商城网站设计实训报告wordpress 仿虎嗅主题
  • 布吉做棋牌网站建设有哪些公司WordPress自动发英文文章
  • 谷歌浏览器对做网站有什么好处效果好的郑州网站建设
  • wap网站开发培训邯郸移动网站制作
  • 小企业网站建设设计阿里云手机做网站
  • 怎么做福利视频网站网站搭建报价表
  • 服务器做ssr后还可以做网站吗玉田县网站建设
  • 东莞市塘厦网站建设不用写代码可以做网站的软件
  • 网站开发有哪些架构国家建设公债拍卖网站
  • 龙华网站建设公司特色美食网站建设
  • 谁知道陕西省建设监理协会的网站广州sem代运营推广公司
  • 深圳网站建设制作报价wordpress图片lazyload