原此航的博客
yuancihang · 共 61 篇文章
[置顶] 我的开源项目
happyxml 项目地址:https://github.com/yuancihang/happyxml 简介:短小精悍的xml操作封装, 只有几百行代码. 支持注解绑定到对象 happyjdbc 项目地址:https://github.com/yuancihang/happyjdbc 简介:简化jdbc操作,提供更现代化的api, 支持分库分表 happyhttp 项目地址:https://github.com/yuancihang/happyhttp 简介:简单而强大的http client 库 ==============================================…
2011-04-14 17:11 · java · 评论(0)
netty vs jetty
对比版本netty4.1 , jetty9.3 1.socket连接处理 jetty 使用AbstractConnector.Acceptor来处理连接, 线程数=Math.max(1, Math.min(4,cores/8)), 但是自己不new线程而是从共享的QueuedThreadPool中拿线程来执行 netty 使用一个单独的NioEventLoopGroup来处理。 NioEventLoopGroup是一个Selector线程池, 其中每个NioEventLoop都表示一个Selector线程。 默认会初始化(cores*2)个NioEventLoop, 但是绑定一个端口只会使用…
如何将资源消耗定位到进程
1. 按CPU消耗给进程排序 top 按P排序 2. 按内存消耗给进程排序 top 按M排序 3. 按TCP连接数消耗给进程排序 netstat -anltp|grep ESTABLISHED|awk -F" " '{a[$7]++}END{for(i in a)print i,a[i]}' |sort -n -k 2 -t ' ' -r 4. 按文件描述符个数消耗给进程排序 lsof|sed '1d'|awk -F" " '{a[$1]++;b[$1]=$2;c[$1]=$3}END{for(i in a)print i,b[i],c[i],a[i]}' |sort -n -k 4 -t …
2017-02-27 15:03 · linux · 评论(0)
采集数据命令备忘
1. 采集CPU数据,每隔2秒采集一次,采集500次。缺点是不知道哪个进程造成的CPU消耗 vmstat -n 2 500 > cpu.txt & 2. 采集网卡数据。每隔2秒采集一次,采集500次 sar -n DEV 2 500|grep eth0 > net.txt & 3. 采集内存数据。每隔5秒采集一次,采集200次。JAVA内存一般变化频率不大,采集间隔过小意义不大 该命令优点是可以看到JAVA进程内部内存的详细分配情况,缺点是看不到直接内存(堆外内存) jstat -gc ${java_pid} 5000 200 > mem.txt & 4. 采集CPU数据。每隔2秒采集一次,…
2017-02-27 14:15 · linux · 评论(0)
目录下所有jar拼接classpath脚本
windows: set MY_HOME=%~dp0 @setlocal EnableExtensions EnableDelayedExpansion set CLASSWORLDS_JAR=. for /F %%i in ('dir /a-d/b/s ..\lib\*.jar') do set CLASSWORLDS_JAR=!CLASSWORLDS_JAR!;%%i echo %CLASSWORLDS_JAR% linux: MY_HOME=$(cd "$(dirname $0)/../";pwd ) echo $MY_HOME CLASSWORLDS_JAR=. for i in $…
2017-02-27 11:03 · script · 评论(0)
新的开源项目happyxml
happyxml 项目地址:https://github.com/yuancihang/happyxml 短小精悍的xml操作封装, 只有几百行代码. 支持注解绑定到对象 public static void sampleQuery() { Dom root = Dom.parse(Paths.get("src/main/resources", "person.xml").toAbsolutePath()); System.out.println(root.childText("firstname")); Dom lastnameDom = root.findChild("lastname"…
2016-11-30 02:21 · java · 评论(0)
新的开源项目happyjdbc
happyjdbc 项目地址:https://github.com/yuancihang/happyjdbc 简化jdbc操作,提供更现代化的api, 支持分库分表 public class DataExample { public static void main(String[] args) throws SQLException { DataAccess.getInstance().addDataSource("local", buildDataSource()); sampleShare(); } private static DataSource buildDataSource()…
2016-11-27 23:18 · java · 评论(0)
我的新的开源项目happyhttp上线了
happyhttp 简单而强大的http client 库 项目地址:https://github.com/yuancihang/happyhttp public static void sampleGet(){ String text = HttpBuilder.newGet("http://www.xxx.com/").execute().getBodyAsText(); System.err.println(text); } public static void samplePost(){ HttpResponse response = HttpBuilder .newPost("ht…
2016-11-26 21:10 · java http · 评论(1)
protobuf通信消息设计技巧备忘
1. 有一个全局的ProtobufMessage, 所有的requestXXX, responseXXX都作为他的一个可选属性, 这样简单粗暴的避免了需要二次序列化反序列化的恶心问题 2. 有一个CommonMessage作为他的一个字段,用来存放公共字段。变相解决了reuqest消息和response消息的继承问题 3. 这样之后对于wireshark抓包后,反序列化以及格式化为JSON极其便利 syntax = "proto3"; option java_package = "com.example.foo"; option java_outer_classname = "Ponycop…
2016-11-14 02:12 · java · 评论(0)
appsecret与accessToken生成
apache oltu: accessToken=md5(UUID.randomUUID().toString()) refreshToken=md5(UUID.randomUUID().toString()) tomcat: sessinid : SecureRandom SHA1PRNG java: private static String genKEY(String algorithm) throws NoSuchAlgorithmException{ KeyGenerator kg = KeyGenerator.getInstance(algorithm);//HmacMD5,Hm…
2016-11-13 11:14 · java · 评论(0)
eclipse 搜索所有非注释中文
项目需要多语言支持,需要把代码中写死的中文抽出来,由于注释中的中文也非常多,所以在搜索的时候要排除注释中的中文。 代码中的字符串与注释中的字符串最大的区别是 代码中的字符串都是以双引号开始的,所以只要在正则表达式中使用双引号即可轻松排除掉注释,不论是多行注释/***/还是单行注释//. 最终正则表达式:"[ \w\_【】\[\]]*[\u4e00-\u9fa5]+ 为了加快搜索速度可以使用eclipse的局部搜选, 1. 先选中一个工程或者目录 2. 在scope区域选中selected resources 这样就不会在整个workspace搜索了。
2016-10-20 01:42 · eclipse · 评论(0)
使用POI读取100万行excel
poi 的usermodel api读取大数据量excel会导致OOM,可以使用eventmodel api来处理这种excel. import java.io.IOException; import java.io.InputStream; import java.util.LinkedList; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.…
2016-07-01 18:21 · java · 评论(2)
Protostuff序列化与反序列化
发现一个好东西Protostuff, 据说可以不写proto文件来把对象序列化成二进制格式,用了一下果然好使。 public class Protostuff { @SuppressWarnings("unchecked") public static <T> byte[] serial(T obj) { Class<T> clazz = (Class<T>) obj.getClass(); // RuntimeSchema会缓存类信息,不用自己实现缓存了,爽 Schema<T> schema = RuntimeSchema.getSchema(clazz); // 缓存buff, 不够会自…
2016-02-23 00:42 · java · 评论(0)
mysql5.7安装
mysql5.7解压之后是没有data目录的 1. 初始化data目录 mysqld --initialize --user=mysql --console 执行后生成data目录 同时生成三个数据库 information_schema,mysql 和performance_schema 2.修改root密码 启动服务器 mysqld --skip-grant-tables --console mysql 不带没密码登录 use mysql; update user set authentication_string=password('123456') , password_expire…
2016-01-30 00:54 · 评论(0)
java 字符串拼接方法性能大比拼
由于在实际项目中经常会打log,这 就要用到字符串拼接, 本文测试了JAVA中的四种字符串拼接方法的性能。 1.使用“+”拼接字符串 public static String f1(String p1, String p2, String p3){ return "["+p1+"]["+p2+"]["+p3+"]"; } 2.使用StringBuilder拼接字符串 public static String f2(String p1, String p2, String p3){ StringBuilder sb = new StringBuilder(); sb.append("[").a…
2015-11-24 11:11 · java · 评论(2)