我的代码:
OkHttpClient client = new OkHttpClient();
HttpUrl httpUrl = HttpUrl.parse(url).newBuilder().addQueryParameter("t", Base64.encodeBase64String(value.getBytes())).build();
Request request = new Request.Builder().url(httpUrl).get().build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
} catch (Exception e) {
System.out.println(e.toString());
}
在Java 8 + apache-tomcat-9.0.14 + okhttp 3.13.1上使用此代码
重新部署日志中的错误:
06-Feb-2019 01:44:05.257 WARNING [Catalina-utility-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [...] appears to have started a thread named [OkHttp ConnectionPool] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:460)
okhttp3.ConnectionPool.lambda$new$0(ConnectionPool.java:66)
okhttp3.ConnectionPool$$Lambda$143/649093426.run(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
06-Feb-2019 01:44:05.260 WARNING [Catalina-utility-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [...] appears to have started a thread named [Okio Watchdog] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:348)
okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:313)
06-Feb-2019 01:44:05.260 WARNING [Catalina-utility-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [...] appears to have started a thread named [OkHttp ConnectionPool] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
我尝试在上下文关闭中使用强制关闭(来自官方javadoc),但仍收到警告。