public static Response syncGet(URL url) throws IOException {
log.debug("http url:{}", url);
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(15L, TimeUnit.SECONDS)
.readTimeout(30L, TimeUnit.SECONDS).build();
Request request = new Request.Builder().url(url).get().addHeader("cache-control", "no-cache").build();
Call call = client.newCall(request);
return call.execute();
}
2019-12-05 11:20:56.068 ERROR 18484 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) [na:1.8.0_181] at java.lang.Thread.start(Thread.java:717) [na:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957) [na:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1378) [na:1.8.0_181] at okhttp3.ConnectionPool.put(ConnectionPool.java:153) ~[okhttp-3.12.1.jar:na] at okhttp3.OkHttpClient$1.put(OkHttpClient.java:167) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:266) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.12.1.jar:na] at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.12.1.jar:na] at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254) ~[okhttp-3.12.1.jar:na] at okhttp3.RealCall.execute(RealCall.java:92) ~[okhttp-3.12.1.jar:na] at chances.cms.util.HttpUtil.syncGet(HttpUtil.java:67) ~[classes/:na] at chances.cms.task.CheckTask.checkContent(CheckTask.java:76) ~[classes/:na] at chances.cms.task.CheckTask.check(CheckTask.java:60) ~[classes/:na] at chances.cms.task.CheckTask.check(CheckTask.java:51) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_181] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_181] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_181] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
OkHttpClients应共享
当您创建一个OkHttpClient实例并将其用于所有HTTP调用时,OkHttp性能最佳。这是因为每个客户端都持有自己的连接池和线程池。重用连接和线程可以减少延迟并节省内存。
更多详细信息:https://square.github.io/OKHTTP/3.x/OKHTTP/OKHTTP3/OKHTTPClient.html
问题内容: 我看到这样的评论 我见过这个问题的一个地方是,如果您继续创建线程,而不是直接在线程对象上调用run(),而不是调用start()。这将导致线程对象不被取消引用…因此,一段时间后,出现无法创建新本机线程的消息 在Sun Java论坛上 在我的应用程序中,最初我们计划使用线程,但是后来,我们决定不再需要线程,因此我们只调用run()而不是start()。我们是否需要为新的threadCla
在大约1024个线程之后,我们在jboss上得到了“java.lang.OutofMemoryError:无法创建新的本机线程”,因为应用程序消耗了最大的用户进程 你能帮我弄清楚代码哪里不对吗?在service.shutdown()之后,我应该添加tasks.clear()还是tasks.remove(ctgService)? 谢谢。
我试图在(1and1VPS)上运行服务器。就在服务器启动和客户机的几个请求(重新加载网页)之后,我得到了这个错误: 但是当我在计算机上运行时,一切都正常。我使用和Centos5.8新安装制作了自己的虚拟服务器,它也在那里工作。 这个内存不足错误的原因可能是什么?如果你有任何建议,请分享。我不知道该怎么处理这个了。
它的发生是因为我创建了许多线程,而没有关闭它们?还是经常创造新的? 有人能告诉我在代码中是否做错了什么吗?
最近更新到Android2.2。 尝试打开现有项目。它提示我转换,我接受了。该项目导入成功,但每当我尝试构建时,我都会得到: 我补充说: gradle.properties.尽管如此,它还是没有奏效。