我有一个程序每分钟调查一次比特币价格信息。运行约2小时后,它会冻结。
我发现execute
类的方法CloseableHttpClient
导致它冻结。我通过输入很多印刷语句找到了这个。 (程序在eclipse中运行)
public PriceTicket[] getFirstDaysSale() throws IOException {
////////////////////////////////////////////////////////
// Gdet first curser for price data
HttpGet getRequest = new
HttpGet("https://api.exchange.coinbase.com/products/BTC-USD/trades");
System.out.print("create athentication");
Authentication.setNonAuthenticationHeaders(getRequest);
CloseableHttpClient temp = HttpClients.createDefault();
String g;
System.out.print("Startexec");
//PROGRAM WILL FREEZE HERE
CloseableHttpResponse response = temp.execute(getRequest);
System.out.print("end exec");
Header h = response.getFirstHeader("CB-AFTER");
nextCurId=h.getValue();
System.out.print("create reader");
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
System.out.print("create json");
String json = processStream(br);
Gson gson = new Gson();
PriceTicket[] priceData = gson.fromJson(json, PriceTicket[].class);
return priceData;
}
控制台输出:
......
......
create athentication
Startexec
程序在此处停止