Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

阿杜 duqicauc

🎯
Focusing
View GitHub Profile
@duqicauc
duqicauc / PermTool.java
Created Sep 1, 2018
利用SA打印jvm中加载的类
View PermTool.java
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.Tool;
/**
* @author duqi
* @createTime 2018/9/1 下午11:55
**/
public class PermTool extends Tool {
@Override
@duqicauc
duqicauc / List2Map.java
Created Aug 16, 2018
List转换成Map,以List里元素的某个字段未key
View List2Map.java
public class List2MapExample {
public static void main(String[] args) {
List<ClassRecordDTO> list = new ArrayList<>();
list.add(new ClassRecordDTO(1, 2, "xxx", 0.0, 0.0));
list.add(new ClassRecordDTO(1, 2, "yyy", 0.0, 0.0));
list.add(new ClassRecordDTO(2, 3, "zzz", 0.0, 0.0));
Map<String, ClassRecordDTO> result = list.stream().collect(Collectors.toMap(ClassRecordDTO::getClassName, classRecordDTO -> classRecordDTO));
@duqicauc
duqicauc / ClassNameUtil.java
Created Aug 15, 2018
将类的JVM规范名称转换为SimpleName
View ClassNameUtil.java
import com.google.common.collect.ImmutableMap;
import java.util.Map;
/**
* @author duqi
* @createTime 2018/8/14 下午3:18
**/
public class ClassNameUtil {
@duqicauc
duqicauc / WatcherMonitorExample.java
Created Jul 25, 2018
使用WatcherMonitor监控某个目录下文件的创建
View WatcherMonitorExample.java
public static void main(String[] args) {
WatchMonitor watchMonitor = WatchMonitor.create("/Users/duqi/", WatchMonitor.ENTRY_CREATE, WatchMonitor.ENTRY_DELETE);
watchMonitor.setWatcher(new Watcher() {
@Override
public void onCreate(WatchEvent<?> event, Path currentPath) {
System.out.println("create1 current time:" + System.currentTimeMillis());
System.out.println("文件创建:" + currentPath);
System.out.println("create2 current time:" + System.currentTimeMillis());
}
@duqicauc
duqicauc / AsyncHttpClientFactoryBean.java
Created Jul 14, 2018
异步http客户端构建工厂
View AsyncHttpClientFactoryBean.java
/**
* Created by IntelliJ IDEA.
* User: duqi
* Date: 2017/2/9
* Time: 15:06
*/
public class AsyncHttpClientFactoryBean implements FactoryBean<CloseableHttpAsyncClient> {
private static final int DEFAULT_MAX_TOTAL = 512;
private static final int DEFAULT_MAX_PER_ROUTE = 64;
@duqicauc
duqicauc / HttpClientFactoryBean.java
Created Jul 14, 2018
http客户端构建工厂
View HttpClientFactoryBean.java
/**
* Created by IntelliJ IDEA.
* User: duqi
* Date: 2017/2/9
* Time: 13:54
*/
public class HttpClientFactoryBean implements FactoryBean<HttpClient> {
// 知识点1:路由(MAX_PER_ROUTE)是对最大连接数(MAX_TOTAL)的细分,整个连接池的限制数量实际使用DefaultMaxPerRoute并非MaxTotal。
// 设置过小无法支持大并发(ConnectionPoolTimeoutException: Timeout waiting for connection from pool),
@duqicauc
duqicauc / AsyncThreadExecutor.java
Created Jul 14, 2018
自定义的异步线程池组件
View AsyncThreadExecutor.java
public class AsyncThreadExecutor implements AutoCloseable {
private static final int DEFAULT_QUEUE_SIZE = 1000;
private static final int DEFAULT_POOL_SIZE = 10;
@Setter
private int queueSize = DEFAULT_QUEUE_SIZE;
@Setter
You can’t perform that action at this time.