zoukankan      html  css  js  c++  java
  • Java-学习日记(抽象类,Spring注释,ConcurrentHashMap)

    9.17学习知识点:abstract,抽象类,@FunctionalInterface,ConCurrentHashMap

    写这篇文章主要是今天没读懂下面的代码,然后就进行了剖析

    @Autowired
    @Qualifier("statisticJdbcTemplate")
    private JdbcTemplate statisticJdbcTemplate;
    
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(statisticJdbcTemplate);
            Map<String, Object> params = new HashMap<>();
            params.put("beginDate", beginDate);
            params.put("endDate", endDate);
            ConcurrentHashMap<String, Long> statisticMap = new ConcurrentHashMap<>();
            statisticMap.put("totalCount", 0L);
            ArrayList<RentRecord> rentRecords = new ArrayList<>();
            namedParameterJdbcTemplate.query(QueryRentRequest(), params, rs -> {
                RentRecord rentRecord = CommonUtils.parseResult(rs, RentRecord.class);
                buildRentDetails(rentRecord);
                rentRecords.add(rentRecord);
                if (rentRecords.size() == pageSize) {
                    saveRentRecord(statisticMap, rentRecords);
                }
            });
    
    1. 首先namedParameterJdbcTemplate是基于JdbcTemplate,对其封装了,内部有query(SQL, Map, 处理数据)函数返回多行数据,,

    2. 而rs->{}就是new Runnable(){}一个新线程,所以就需要后续的ConcurrentHashMap,HashMap.put方法在并发下可能会导致死循环,而ConcurrentHashMap基于并发分离锁,属于非阻塞,例如当线程A在pull的时候,线程B只能getA已经成功插入的数据.

    abstract

    (Java接口方法默认都是public abstract,有abstract的方法必须要是抽象类。虚函数一般与多态结合起来说,java类都是虚函数,而所谓多态,就是同一接口,不同操作,有3大必要条件

    • 继承

    • 重写

    • 基类引用指向派生类对象(引用还是指向基类

      Parent p = new Child();//父类指子类
      

    @FunctionalInterface

    函数式接口:这里就是Lambda里面的内容了,接口有且仅有一个抽象方法abstract,

    @FunctionalInterface
    public interface PageCountHelper {
        Long pageCount(Query query);
    }
    
    PageCountHelper pageCountHelper = (Query query) -> dao.pageCountA(query);
    
  • 相关阅读:
    POJ3233 构造子矩阵+矩阵快速幂
    HDU4565-数学推导求递推公式+矩阵快速幂
    记录一个状压DP用到的骚操作
    POJ1273 最大流模板
    图论复习...
    2017-7 实训经验贴
    Polya定理应用实例
    直线,椭圆,三角形,折线分割平面问题
    hdu4801 PocketCube 2阶魔方
    1256:献给阿尔吉侬的花束
  • 原文地址:https://www.cnblogs.com/meditation5201314/p/13692201.html
Copyright © 2011-2022 走看看