Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 517174a

Browse files
committed
优化代码
1 parent 1fbeed4 commit 517174a

2 files changed

Lines changed: 8 additions & 17 deletions

File tree

src/main/java/com/zhazhapan/util/NetUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static String getMacAddress() throws UnknownHostException, SocketExceptio
6969
/**
7070
* 获取公网IP
7171
*
72-
* @return 公网ip、address
72+
* @return 公网ip、address,如:{"ip":"127.0.0.1","address":"you ip location"}
7373
*/
7474
public static JsonParser getPublicIpAndLocation() throws IOException {
7575
return new JsonParser(new URL(ValueConsts.URL_OF_PUBLIC_IP_SEARCH));

src/main/java/com/zhazhapan/util/ThreadPool.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ public class ThreadPool {
1818
private static int maximumPoolSize = 3;
1919
private static long keepAliveTime = 1000;
2020
private static TimeUnit timeUnit = TimeUnit.MILLISECONDS;
21-
private static BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(1);
22-
private static ThreadFactory threadFactory = new ThreadFactory() {
23-
@Override
24-
public Thread newThread(Runnable r) {
25-
return new Thread(r);
26-
}
27-
};
21+
private static BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(1);
22+
private static ThreadFactory threadFactory = Thread::new;
2823
/**
2924
* 新的线程池
3025
*/
31-
public ThreadPoolExecutor newExecutor = null;
26+
public ThreadPoolExecutor newExecutor;
3227

3328
/**
3429
* 新建线程池
@@ -39,21 +34,17 @@ public Thread newThread(Runnable r) {
3934
* @param unit 存活时长单位
4035
*/
4136
public ThreadPool(int core, int maximum, int keep, TimeUnit unit) {
42-
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(1);
43-
ThreadFactory factory = new ThreadFactory() {
44-
@Override
45-
public Thread newThread(Runnable r) {
46-
return new Thread(r);
47-
}
48-
};
37+
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(1);
38+
ThreadFactory factory = Thread::new;
4939
newExecutor = new ThreadPoolExecutor(core, maximum, keep, unit, queue, factory);
5040
}
5141

5242
/**
5343
* 初始化线程池
5444
*/
5545
public static void init() {
56-
executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, timeUnit, workQueue, threadFactory);
46+
executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, timeUnit, workQueue,
47+
threadFactory);
5748
}
5849

5950
/**

0 commit comments

Comments
 (0)