zoukankan      html  css  js  c++  java
  • 子线程指令重排

    CountDownLatch countDownLatch = new CountDownLatch(1);

    try{
    boolean anotherDay = checkAnotherDay();
    try{
    if(anotherDay) {
    String logUrlYestoday = logUrl;
    int index = logUrlYestoday.lastIndexOf(".");
    StringBuilder stringBuilder = new StringBuilder(100);
    stringBuilder.append(logUrlYestoday.substring(0, index+1)).append(dateIbFormate.format(lastTime)).append(".log");

    int res = readLogFile(stringBuilder.toString(), false);
    if(res == 0) {
    logger.info("read yesterday success");
    } else {
    logger.error("read yesterday error, {}", res);
    }
    }
    } catch (Exception e) {
    logger.error(e.getMessage(), e);
    } finally {
    countDownLatch.countDown();
    }

    countDownLatch.await();

    readLogFile(logUrl, true);

    } catch (Exception e) {
    logger.error(e.getMessage(), e);
    }

      

    在未使用CountDownLatch前,有出现最后一行

    readLogFile

     

    的数据先于前面的代码数据执行插入操作了,故为了确保数据有序性,加入CountDownLatch

     

    性质有点像:https://www.cnblogs.com/silyvin/p/9106641.html

    
    
  • 相关阅读:
    MYSQL索引使用
    事务的概念是什么,有哪些基本属性?
    springboot和springmvc的区别
    List、Map、Set的区别与联系
    MyBatis-动态SQL
    MyBatis-映射文件
    MyBatis操作数据库及全局配置文件
    Jmeter的基本使用
    MySQL索引优化
    MySQL索引
  • 原文地址:https://www.cnblogs.com/silyvin/p/9448012.html
Copyright © 2011-2022 走看看