
java机制学习
Kevins Danish
玩转原生代码
展开
-
mysql正则匹配单个字符-神坑!
—在这里插入图片描述问个问题 mysql 我想匹配的字段 只存在一个“/” sql 怎么写?select * from table where path regexp ‘/{1}’ ?可适用如下select * from user where name regexp '^[^/]+(/{1})[^/]+$';...原创 2019-09-17 16:47:03 · 2452 阅读 · 0 评论 -
记java工作中的坑
使用json中public static <T> T reSerializableJson(String jsonStr, TypeReference<T> type) { return JSONArray.parseObject(jsonStr, type); }这里将默认使用HashMap, 如果我们的类字段使用ConcurrentH...原创 2019-09-18 15:11:56 · 1788 阅读 · 0 评论 -
一种java对象转换成protobuf对象通用方法(bean转protobuf 类)
ps:该文默认读者熟悉protobuf直入正文, 总共2个类,一个是注解类,一个是工具类注解类 @ProtoField有两个作用1.标识某个bean的属性忽略转化 Ignore2.标识某个List属性对应proto文件中的哪个属性名,对应proto文件哪个协议类该类的创建模仿于fastjson中的JSONField, 源码如下:import java.lang.annotation...原创 2019-07-14 13:35:40 · 6282 阅读 · 4 评论 -
poi解析excel,将每一行数据注入到对应的entity实体对象对象中
贼好用的代码,直接上辽public class GameScene { public int id; public String name; public String getName() { return name; } public void setName(String name) { this.name = ...原创 2019-07-02 22:02:40 · 7385 阅读 · 9 评论 -
Native Code To Gget Expensive Resource Such As Database Connection(Self Protection Mechanism)
emm, in our common application scenario, getting system resource such as database connection seems to be easy , but when we program in high concurrent scenario , it would be disorder. How can we prot...原创 2018-11-30 22:03:37 · 244 阅读 · 0 评论 -
gracefully cancel/shutdown the thread
for something we should care it when you read this article1. Interrupt operation in synchronized code block使用synchronized关键字获取锁的过程中不响应中断请求,这是synchronized的局限性,如果这对程序是一个问题,应该使用显式锁,java中的Lock接口,它支持以响应中...原创 2018-11-29 17:04:14 · 213 阅读 · 0 评论 -
优雅的判空操作_对需要频繁判空的对象entity的代码优化
优雅的判空操作 --> 对需要频繁判空的对象entity的代码优化代码结构entity是本文用到的对象,里面还用到了entityReturn作为field和getEntityReturn的返回值,如下图红框Entity对应的接口:entity是Ientity的实现类,Nullentity也是这个接口实现类相同的,entityReturn也是相似的套路看红色箭头->...原创 2018-11-25 16:48:26 · 1792 阅读 · 1 评论 -
rehash问题小记?
1、为什么hashmap中length是16,resize要是2的幂次的问题**hashcode(key)&amp;amp;(length-1):16-1为二进制的1111,进行与运算的时候能够较为散列地计算key的index值,那为啥resize要2的次幂呢,道理是一样的,扩大2的一次方,length-1就是11111,进行与运算一看就知道。2 高并发下的rehash?**javadoc中关...原创 2018-05-19 22:05:59 · 731 阅读 · 1 评论 -
statement prepareStatement的一点体会?
1、PrepareStatement 是预编译的,对于批量处理(Batch)处理可以大大提高效率,也叫JDBC存储过程2、使用Statement对象。在对数据库只执行一次性存取的时候,用Statement对象进行处理,PrepareStatement对象的开销比Statement大,对于一次性操作并不会带来额外的好处。3、statement每次执行sql语句,相关数据库都要执行sql语句的...原创 2018-05-19 16:55:02 · 923 阅读 · 0 评论