- 博客(503)
- 资源 (40)
- 收藏
- 关注
转载 Java避坑指南:finally块的陷阱及正确的关闭资源方式小
正确的关闭资源方式转载:Java避坑指南:finally块的陷阱及正确的关闭资源方式小结1、使用finally块来关闭资源,保证关闭操作总是会被执行;2、关闭每个资源之前首先判断资源的引用变量不为null,避免NPE发生;3、为每个资源使用单独的try...catch 块关闭,保证关闭此资源发生异常,不会影响后面资源的关闭;4、finally块不要使用return语句。return语句直接导致方法结束,不会再跳回去执行try、catch块中的任何代码;5、不要出现Sy
2022-05-11 16:04:32
1159
原创 ArchUnit在代码检测方面的应用
1、为什么做代码检测功能 不管使用哪种语言,哪种框架,只要你编程,都会遇到些所谓的“坑”,只能靠代码检测工具自动发现这些问题,因为人脑或者是人并不总是最靠谱的。也行你已经用了阿里的检查插件P3C,或者SonarQube、JArchitect、checkstyle或者findbugs等等工具来检测来避免,现在介绍一款java的基于字节码的我们可以自定义的,比较通用的检测工具。2、ArchUnit 使用这个工具的目的,其实想利用java反射的方式,基于字节码解析...
2021-04-26 11:30:44
1134
原创 There are only 1 target objects. You either specified a wrong ‘keyProperty‘ or encountered a driver
1、由于标题限制,详细异常堆栈如下org.apache.ibatis.executor.ExecutorException: Too many keys are generated. There are only 1 target objects. You either specified a wrong 'keyProperty' or encountered a driver bug like #1523. at org.apache.ibatis.executor.keygen.J.
2021-04-17 11:20:54
5393
原创 java并发编程之Future.get() 在线程池配置RejectedExecutionHandler为ThreadPoolExecutor.DiscardPolicy策略时一直阻塞
1、我们先简单复现这种情况:package com.sdcuike.java11;import java.util.concurrent.*;import com.google.common.util.concurrent.ThreadFactoryBuilder;public class Demo { public static void main(String[] args) throws ExecutionException, InterruptedExcepti...
2021-04-13 00:05:56
935
3
原创 性能优化之异步日志
如果项目日志info级别打的特别多的情况下,打印日志也有可能把系统拖垮。 所以项目中一般打印日志会使用异步AsyncAppender打印日志。 先看下官方文档的介绍,AsyncAppender 会把处理的事件缓存到一个阻塞队列,默认情况下达到队列容量的80%的时候,会丢弃TRACE, DEBUG and INFO级别的事件,根据默认配置neverBlock=false,队列也会发生阻塞,所以设置true,虽然完全是非阻塞但会丢失日志,特别是err...
2021-03-27 11:31:21
1213
原创 记录:mysql 批量更新的使用问题,rewriteBatchedStatements
目录一、场景二、问题原因一、场景最近在清洗老数据,为了提高效率,使用了mysql的batch特性:设置关闭自动提交功能:autoCommit = false示例代码:List<Person> persons = ... // get a list of Person objects from somewhere.String sql = "update people set firstname=? , lastname=? where id=...
2020-11-08 23:20:18
2128
原创 Java Memory Model
https://courses.cs.ut.ee/MTAT.03.279/2016_fall/uploads/Main/7-threads-jmm.pdfhttps://github.com/sdcuike/issueBlog/blob/master/7-threads-jmm%20(1).pdfhttps://docs.oracle.com/javase/specs/jls/se7/html/jls-17.htmlhttps://shipi...
2020-07-11 22:57:36
323
原创 android 7.0以上charles https抓包
由于Android7.0之后新版本系统的安全限制,证书必须安装到系统证书目录下:/system/etc/security/cacerts,之前的安装的证书的步骤可能会抓包产生下图问题:Android7.0 之后默认不信任用户添加到系统的CA证书,按之前的步骤即使你在手机上安装了抓包工具的证书也无法抓取 https 请求,但是苹果系统目前还是可以安装的。操作步骤:1、系统首...
2020-04-23 23:18:53
14685
6
原创 Hystrix的使用
Hystrix虽然已经停止更新迭代,进入了维护阶段,替代品Resilience4j成为了首先,但是遗留系统还有必要维护更新的。Hystrix在项目中经常使用的方式主要有三种方式在;1、继承HystrixCommand实现代理类,把之前的业务逻辑写在run()方法内代码示例详见:https://github.com/Netflix/Hystrix/wiki/How-To-Use...
2020-04-12 22:08:05
1187
原创 jvm指令monitorenter,monitorexit与synchronization关键字
monitorenter与monitorexit指令主要和java并发关键字synchronization 在jvm层指令的实现有关系。synchronization 方法的实现并没有采用这两个指令。monitorenter主要是获取监视器锁,monitorexit主要是释放监视器锁。monitorenterOperationEnter monitor for objec...
2020-02-26 00:59:15
7455
2
原创 构建容器的最佳做法
本文介绍构建容器的一系列最佳做法。这些做法涵盖了广泛的目标(从缩短构建时间到创建更小、弹性更佳的映像),旨在使容器更加容易构建(例如,使用Cloud Build),并且更加容易在Google Kubernetes Engine (GKE)中运行。这些最佳做法的重要性并不相同。例如,成功运行某一生产工作负载可能无需其中某些做法,但必须使用其他做法。特别是,与安全相关的最佳做法的重要性较为主...
2020-02-23 17:30:15
808
原创 A few distributed abstractions and primitives from Kubernetes
ContainersContainersare the building blocks for Kubernetes-based cloud-native applications. If we make a comparison with OOP and Java, container images are like classes, and containers are like obj...
2020-02-23 16:53:39
531
原创 Kubernetes Patterns-Distributed Primitives(k8s模式-分布式原语)
To explain what we mean by new abstractions and primitives, here we compare them with thewell-known object-oriented programming (OOP), and Java specifically. In the OOP universe, wehave concepts suc...
2020-02-23 15:53:24
589
原创 java之Compiler control
Controlling Java Virtual Machine (JVM) compilers might seem like an unnecessary task,but for many developers, this is an important aspect of testing. This is accomplished withmethod-dependent compil...
2020-02-07 20:41:45
511
原创 浏览器响应数据long型超长自动转换精度丢失-JavaScript 整数精度丢失问题-springboot解决Long类型数据传入前端损失精度
最近在洗敏感数据id,用类似snowflake算法加入分表基因生成新的ID,返回给前端,前端整数显示不正常。java中long的最大值:9223372036854775807看看在浏览器中的显示:Google Chrome版本 79.0.3945.117(正式版本) (64 位)后面好几位不一样了,看看JavaScript中整数的最大值:看来JavaScrip...
2020-01-18 00:26:39
3267
原创 基因分库分表
场景: 数据存储中,相互关系的表,尽量分库时落到同一个库中,避免遍历多个库查询,而且还能避免分布式事务。 一般分库或者分表我们采用取余操作,余数相同的id落到相同的库中,或分表规则一致。解决理论:参考:https://stackoverflow.com/questions/6670715/mod-of-power-2-on-bitwise-operators根据理...
2020-01-17 23:56:30
3800
原创 边车设计模式-Sidecar pattern
Sidecar pattern Sidecar pattern和哈雷车类似原理:把一个应用的不同组件部署到不同的进程或容器中,以提供隔离和封装,应用的各个组件各自维护更...
2019-12-19 23:46:22
5201
原创 性能优化之写时复制(Copy-on-write:COW)
写入时复制(英语:Copy-on-write,简称COW)是一种计算机程序设计领域的优化策略。其核心思想是,如果有多个调用者(callers)同时请求相同资源(如内存或磁盘上的数据存储),他们会共同获取相同的指针指向相同的资源,直到某个调用者试图修改资源的内容时,系统才会真正复制一份专用副本(private copy)给该调用者,而其他调用者所见到的最初的资源仍然保持不变。这过程对其他的调用者都...
2019-12-15 21:51:22
3952
1
原创 Maven: Transitive Dependencies
Dependencies declared in your project’s pom.xml file often have their own dependencies . Such dependencies are called transitive dependencies . Take the example of Hibernate Core. For it to function p...
2019-11-30 18:28:57
821
原创 spring boot 目录浏览功能 How to enable directory listing in Spring Boot
@Componentpublic class CustomizationBean implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> { @Override public void customize(TomcatServletWebServerFactory factory) {...
2019-11-29 14:05:50
1487
1
原创 java9新特性-Stack Walking-当前线程栈信息
java语言是基于栈的设计语言,其执行的本质与c、c++语言一样,程序的运行都是一系列进栈出栈操作。JVM中的每个线程启动时都有一个私有的JVM线程栈会创建。栈这种数据结构就是我们常谈到的数据结构中的栈-后进先出的数据结构。栈保存了一系列栈帧,每当一个方法执行时都会伴随着新的栈帧的创建并进栈顶,方法执行完也都会伴随着对应的栈帧的销毁-出栈操作。有关具体细节可以参考https://docs.orac...
2019-10-26 23:49:22
689
原创 java9新特性-增强的try-with-resources块
java7新增了自动关闭资源的特性,碰到异常的时候,我们不必再写一堆啰嗦的处理代码,而是简洁的如下: try (ServerSocket socket = new ServerSocket(8090)) { System.out.println(socket); }或者多个资源的情况下: try (ServerSocket socket = ...
2019-10-22 01:08:37
602
原创 java10新特性:本地变量(local variable)-var类型推断
本地变量(local variable)-var类型推断,一种java语法糖,编译器根据代码上下文信息--字面量值、方法调用、声明等,推断变量类型,并且把类型信息添加到对应的生成的字节码里。先来个例子:public class TypeInference { public static void main(String[] args) { var time = L...
2019-10-19 20:06:51
5927
原创 Spring MVC @JsonView使用详解
@JsonView jackson注解官方文档:public @interface JsonViewAnnotation used for indicating view(s) that the property that is defined by method or field annotated is part of.An example annotation would be:...
2019-10-13 11:07:31
2397
1
原创 java非静态内部类中的属性this$0
Effective java 第三版第24条:Item 24: Favor static member classes over nonstatic优选考虑使用静态成员类静态成员类是最简单的一种嵌套类。和普通的外层类一样,只是碰巧被声明在另一个类的内部而已,而且还带有点特殊技能:可以访问外层类的所有成员(包括私有的)。非静态成员类的每个实例都隐含着与外层类的一个外层类实例(在jdk...
2019-10-07 22:51:26
5991
原创 聊聊JVM Young Gen(年轻代)Eden区的线程本地分配缓冲区-TLAB(Thread Local Allocation Buffer)
JVM一般采用分代来管理堆内存,如下图: 逻辑上是连续的,但不同的gc回收算法在实际分配内存时不一定是连续的。一般大部分对象都在年轻代中的Eden区创建,除个别大对象直接在老年代分配。因为堆是共享的,多个线程可以同时创建对象,为了保证线程安全,Eden区又被分配成一个个线程本地分配缓冲区-TL...
2019-10-03 16:55:18
1420
原创 java 泛型参数具体类型获取、泛型返回具体类型获取
自从java支持泛型后,现在,spring生态中的框架及目前的应用都使用了泛型。有的框架如mybatis和spring都需要反射获取类型,以使得序列化和反序列化得以实现,但有时候我们根据项目的需要获取这些具体类型。比如,mybatis orm环境下,数据库字段类型和java类型不匹配检测的功能,需要利用这种方法获取类中方法的具体类型,结合com.mysql.cj.MysqlType枚举中类型...
2019-09-30 17:28:00
10695
1
原创 数据源组件druid filter的扩展机制及spring boot 环境下的几种配置方式
Druid的监控统计功能是通过filter-chain扩展实现,filter给开发者带来了很好的扩展性,使得我们可以自定义实现一些功能。在spring boot环境下,除了系统环境变量及jdbc url方式配置filter,大多常用的有以下几种:(1)在项目中像平时写类加注解的方式例如:@Componentpublic class DemoFilter exte...
2019-08-25 20:33:37
5004
1
原创 spring 容器中Bean的生命周期图谱
The Spring application context uses the Factory method design pattern tocreate Spring beans in the container in the correct order according to thegiven configuration. So the Spring container has the...
2019-08-11 19:50:14
335
原创 java并发之synchronized解密
目录synchronized关键字主要用在4个地方:1.实例方法2.静态方法3.实例方法中的代码块4.静态方法中的代码块监视器锁(monitor lock)所属的对象是不同的JVM内部如何实现的(1)实例方法中的代码块和静态方法中的代码块通过指令monitorenter和monitorexit实现的(2)实例方法和静态方法JVM特殊处理,并没有相应的JVM...
2019-07-21 20:09:07
441
原创 java开发规则:线程如何被创建
目录1、创建线程请使用线程工厂类(1)自定义线程工厂参照java.util.concurrent.Executors类中的线程工厂(2)建议使用org.apache.commons.lang3.concurrent.BasicThreadFactoryapache lang3 工具包已经提供了一个自定义线程的工厂类,所以,我们放心的使用吧。2、设置线程的UncaughtEx...
2019-07-21 00:09:29
545
转载 Why you should avoid conditional statements
Developers tend to use a lot of conditional statements in their code. Of course, each flow has one specific path, its own specific validations, etc. It is very natural that your code has a lot of deci...
2019-05-16 14:08:39
371
转载 8 design patterns that every developer should know
8 design patterns that every developer should knowAs a developer, you are constantlyresolving problems. Many of these problems probably werealready solved by other developers, so, why do w...
2019-05-15 23:35:07
329
转载 Cloud Design Patterns
目录 Cloud Design Patterns1. Availability patterns(1) Health Endpoint Monitoring pattern(2)Queue-Based Load Leveling pattern(3)Throttling pattern 2.Da...
2019-05-14 22:06:35
1034
转载 Ten design principles
Ten design principles目录 Ten design principlesDesign for self healing RecommendationsMake all things redundantR...
2019-05-05 21:17:17
757
转载 Architecture styles
Architecture styles目录 Architecture stylesA quick tour of the stylesN-tierWeb-Queue-WorkerMicroservicesCQRSEvent...
2019-05-05 19:59:50
678
转载 Go’s Philosophy on Concurrency
Go’s Philosophy on ConcurrencyCSP was and is a large part of what Go was designed around; however, Go also sup‐ports more traditional means of writing concurrent code through ...
2019-04-30 17:45:37
295
转载 5 great programming techniques every developer should know
5 great programming techniques every developer should know1 – Encapsulate ifs inside their methods, not outside them:Bad example:? 1 2 3 4 5 6 7 8 9 ...
2019-04-29 16:30:21
222
转载 11 mistakes java developers make when using exceptions
11 mistakes java developers make when using exceptionsThe problem: If you use Exceptions in the wrong way, bugs will be very difficult to find. If you always use generic Exceptions, how can oth...
2019-04-29 16:23:13
275
原创 Kafka消费积压Lag值Python代码获取
Kafka消费积压Lag值Python代码获取 背景 根据kafka的消息堆积情况,自动扩容消费者集群实例数目。 代码及测试from kafka import KafkaConsumerfrom kafka import KafkaProducerfrom kafka import To...
2019-04-24 10:56:15
5061
2
Packt.Mastering.Java.9.1786468735.zip
2019-09-07
Java 9 Dependency Injection - Nilang Patel.pdf.zip
2019-09-07
Spring 5 Recipes A Problem-Solution Approach.zip
2019-09-03
Syngress.SQL.Injection.Attacks.and.Defense.2nd.Edition.1597499633.zip
2019-08-31
Syngress.SQL.Injection.Attacks.and.Defense.2nd.Edition.1597499633.epub
2019-08-31
Syngress.SQL.Injection.Attacks.and.Defense.2nd.Edition.1597499633.mobi
2019-08-31
OCP Java SE 8 Programmer II Exam Guide.pdf
2019-07-14
Learn Java 12 Programming.epub
2019-07-13
Social Network-Based Recommender Systems
2018-04-07
The Robert C. Martin Clean Code Collection.
2018-02-03
Hadoop Explained.pdf )
2018-02-03
Java Deep Learning Essentials.epub
2018-02-03
Mastering Microservices with Java.pdf
2018-02-03
Mastering Microservices with Java.mob
2018-02-03
Advanced Data Structures and Algorithms 9789355517937
2023-06-22
Java.9.0.to.17.0.Cookbook
2023-02-25
Learn Docker - Fundamentals of Docker 18.x 2018.pdf.zip
2020-02-08
逆流而上 阿里巴巴技术成长之路.pdf.zip
2020-02-08
Introducing Maven, 2nd Edition.epub
2019-11-30
Packt.Design.Patterns.and.Best.Practices.in.Java.9.1786463598.epub.zip
2019-09-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人