java小知识

介绍

这是平常的小知识介绍延续上一篇https://blog.youkuaiyun.com/shen_yun2017/article/details/103276624

Map 类集合 K/V 能不能存储 null 值的情况,如下表格:

在这里插入图片描述

try-with-resource

实现Autocloseabls接口的close方法,讲try-catch-finally的finally关闭资源放入close方法中。

此处代码原文链接:https://blog.youkuaiyun.com/weixin_40255793/article/details/80812961
public class Main {

    public static void startTest() {
        try (MyAutoCloseA a = new MyAutoCloseA();
             MyAutoCloseB b = new MyAutoCloseB()) {
            a.test();
            b.test();
        } catch (Exception e) {
            System.out.println("Main: exception");
            System.out.println(e.getMessage());
            Throwable[] suppressed = e.getSuppressed();
            for (int i = 0; i < suppressed.length; i++)
                System.out.println(suppressed[i].getMessage());
        }
    }

    public static void main(String[] args) throws Exception {
        startTest();
    }
}

/* 输出为:
	MyAutoCloaseA: test()
	MyAutoCloseB: on close
	MyAutoCloseA: on close()
	Main: exception
	MyAutoCloaseA: test() IOException
	MyAutoCloaseB: close() ClassNotFoundException
	MyAutoCloaseA: close() ClassNotFoundException
*/

class MyAutoCloseA implements AutoCloseable {

    public void test() throws IOException {
        System.out.println("MyAutoCloaseA: test()");
        throw new IOException("MyAutoCloaseA: test() IOException");
    }

    @Override
    public void close() throws Exception {
        System.out.println("MyAutoCloseA: on close()");
        throw new ClassNotFoundException("MyAutoCloaseA: close() ClassNotFoundException");
    }
}

class MyAutoCloseB implements AutoCloseable {

    public void test() throws IOException {
        System.out.println("MyAutoCloaseB: test()");
        throw new IOException("MyAutoCloaseB: test() IOException");
    }
    
    @Override
    public void close() throws Exception {
        System.out.println("MyAutoCloseB: on close");
        throw new ClassNotFoundException("MyAutoCloaseB: close() ClassNotFoundException");
    }
}

索引

如果有 order by 的场景,请注意利用索引的有序性。order by 最后的字段是组合索
引的一部分,并且放在索引组合顺序的最后,避免出现 file_sort 的情况,影响查询性能。
正例:where a=? and b=? order by c; 索引:a_b_c

返回值

不允许直接拿 HashMap 与 Hashtable 作为查询结果集的输出。
反例:某同学为避免写一个<resultMap>,直接使用 HashTable 来接收数据库返回结果,结果出现日常
是把 bigint 转成 Long 值,而线上由于数据库版本不一样,解析成 BigInteger,导致线上问题。

阿里名词

  1. CAS(Compare And Swap): 阿里巴巴专指数据库表一一对应的 POJO 类。解决多线程并行
    情况下使用锁造成性能损耗的一种机制,这是硬件实现的原子操作。CAS 操作包含三个操作
    数:内存位置、预期原值和新值。如果内存位置的值与预期原值相匹配,那么处理器会自动将
    该位置值更新为新值。否则,处理器不做任何操作。
  2. DO(Data Object): 阿里巴巴专指数据库表一一对应的 POJO 类。
  3. GAV(GroupId、ArtifactId、Version): Maven 坐标,是用来唯一标识 jar 包。
  4. OOP(Object Oriented Programming): 本文泛指类、对象的编程处理方式。
  5. AQS(AbstractQueuedSynchronizer): 利用先进先出队列实现的底层同步工具类,它是很多上
    层同步实现类的基础,比如:ReentrantLock、CountDownLatch、Semaphore 等,它们通
    过继承 AQS 实现其模版方法,然后将 AQS 子类作为同步组件的内部类,通常命名为 Sync。
  6. ORM(Object Relation Mapping): 对象关系映射,对象领域模型与底层数据之间的转换,本
    文泛指 iBATIS, mybatis 等框架。
  7. POJO(Plain Ordinary Java Object): 在本规约中,POJO 专指只有 setter/getter/toString 的
    简单类,包括 DO/DTO/BO/VO 等。
  8. AO(Application Object): 阿里巴巴专指 Application Object,即在 Service 层上,极为贴近
    业务的复用代码。
  9. NPE(java.lang.NullPointerException): 空指针异常。
    10.OOM(Out Of Memory): 源于 java.lang.OutOfMemoryError,当 JVM 没有足够的内存
    来为对象分配空间并且垃圾回收器也无法回收空间时,系统出现的严重状况。
    11.一方库: 本工程内部子项目模块依赖的库(jar 包)。
    12.二方库: 公司内部发布到中央仓库,可供公司内部其它应用依赖的库(jar 包)。
    13.三方库: 公司之外的开源库(jar 包)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值