Skip to content

Commit

Permalink
improve UserStatUtil. (alibaba#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
XenoAmess authored Oct 13, 2021
1 parent 58b5381 commit b38d9b3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/src/main/java/com/taobao/arthas/core/util/UserStatUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.taobao.arthas.core.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand All @@ -17,6 +16,11 @@
* Created by zhuyong on 15/11/12.
*/
public class UserStatUtil {

private static final int DEFAULT_BUFFER_SIZE = 8192;

private static final byte[] SKIP_BYTE_BUFFER = new byte[DEFAULT_BUFFER_SIZE];

private static final ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Expand Down Expand Up @@ -100,7 +104,7 @@ public void run() {
if (link == null) {
return;
}
BufferedReader br = null;
InputStream inputStream = null;
try {
if (queryData.length() != 0) {
link = link + "?" + queryData;
Expand All @@ -110,18 +114,17 @@ public void run() {
connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
connection.connect();
br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = null;
StringBuilder result = new StringBuilder();
while ((line = br.readLine()) != null) {
result.append(line);
inputStream = connection.getInputStream();
//noinspection StatementWithEmptyBody
while (inputStream.read(SKIP_BYTE_BUFFER) != -1) {
// do nothing
}
} catch (Throwable t) {
// ignore
} finally {
if (br != null) {
if (inputStream != null) {
try {
br.close();
inputStream.close();
} catch (IOException e) {
// ignore
}
Expand Down

0 comments on commit b38d9b3

Please sign in to comment.