DEV Community

小猫先生
小猫先生

Posted on • Edited on

1

Java 小工具

JMH

Another tutorial: JMH - Java Microbenchmark Harness see: Java Samples
JMH 是一个由 OpenJDK/Oracle 里面那群开发了 Java 编译器的大牛们所开发的 Micro Benchmark Framework 。何谓 Micro Benchmark 呢?简单地说就是在 method 层面上的 benchmark,精度可以精确到微秒级。可以看出 JMH 主要使用在当你已经找出了热点函数,而需要对热点函数进行进一步的优化时,就可以使用 JMH 对优化的效果进行定量的分析。

比较典型的使用场景还有:

  • 想定量地知道某个函数需要执行多长时间,以及执行时间和输入 n 的相关性
  • 一个函数有两种不同实现(例如实现 A 使用了 FixedThreadPool,实现 B 使用了 ForkJoinPool),不知道哪种实现性能更好

logback 配置解析

  • 如何引入日志?
  • 日志输出格式以及输出方式如何配置?
  • 代码中如何使用?

Validation

  • @NotNull //不允许为空
  • @Size //长度或大小范围

    @Size(min = 1, max = 20)
    private String name;

  • @NotNull(groups = ValidationService.Save.class) // 保存时不允许为空,更新时允许为空 ,表示不更新该字段

  • @Pattern

    @Pattern(regexp = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$")
    private String email;

  • @Min(18) //最小值

  • @Max //最大值

    @Max(100) private int age;

  • @Past //必须为一个过去的时间

    @Past private Date loginDate;

  • @Future //必须为一个未来的时间

    @Future private Date expiryDate;

Transactional(来源:Spring @Transactional 原理及使用

  • 事务传播行为 事务传播行为
  • 事务隔离级别 事务隔离级别
    • 脏读 : 一个事务读取到另一事务未提交的更新数据
    • 不可重复读 : 在同一事务中, 多次读取同一数据返回的结果有所不同, 换句话说, 后续读取可以读到另一事务已提交的更新数据。相反,” 可重复读” 在同一事务中多次读取数据时,能够保证所读数据一样,也就是后续读取不能读到另一事务已提交的更新数据
    • 幻读 : 一个事务读到另一个事务已提交的 insert 数据
  • 属性 属性

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay