Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.OutOfMemoryError与不协调JDA350+;线程_Java_Multithreading_Discord_Out Of Memory_Discord Jda - Fatal编程技术网

java.lang.OutOfMemoryError与不协调JDA350+;线程

java.lang.OutOfMemoryError与不协调JDA350+;线程,java,multithreading,discord,out-of-memory,discord-jda,Java,Multithreading,Discord,Out Of Memory,Discord Jda,所以我会尽力解释我的问题。目前,我正在进行一个规模相当可观的项目。然而,正如350+所说,我从未使用过这么多线程。它目前给了我一个内存不足的错误,但是我已经尝试了各种选项: 添加-Xss参数 添加我可以在上找到的其他参数 此外,我还试图编辑堆栈大小和用户限制 下面列出了因内存不足而导致的错误 java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resour

所以我会尽力解释我的问题。目前,我正在进行一个规模相当可观的项目。然而,正如350+所说,我从未使用过这么多线程。它目前给了我一个内存不足的错误,但是我已经尝试了各种选项:

  • 添加-Xss参数
  • 添加我可以在上找到的其他参数
  • 此外,我还试图编辑堆栈大小和用户限制

下面列出了因内存不足而导致的错误

java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
        at java.base/java.lang.Thread.start0(Native Method)
        at java.base/java.lang.Thread.start(Thread.java:804)
        at okhttp3.internal.http2.Http2Connection.start(Http2Connection.java:515)
        at okhttp3.internal.http2.Http2Connection.start(Http2Connection.java:499)
        at okhttp3.internal.connection.RealConnection.startHttp2(RealConnection.java:299)
        at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:288)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:169)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:264)
        at okhttp3.RealCall.execute(RealCall.java:93)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:200)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:140)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:123)
        at net.dv8tion.jda.internal.requests.ratelimit.BotRateLimiter$Bucket.run(BotRateLimiter.java:468)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:835)
我发现无论我做什么,线程堆栈的大小总是显示为1024

我目前使用以下规范从VPS运行此.jar文件:

  • 无限流量
  • 32GB内存
  • 600GB固态硬盘
  • 16芯
我的问题是,有没有办法编辑线程堆栈的大小


另一个单独的问题:每当我使用-Xss2g时,它确实会显示它超出了限制,但是有没有办法编辑此限制?

您可以尝试配置JDA并更改默认值以减少内存占用。确保您还使用了最新版本的JDA(目前是4.2.0_252)


阅读常见问题解答:

事实上我已经找到了答案

我托管的提供者(我将不知道其名称)将我可以同时运行的线程数量限制为1300个线程。因为他们的线程数量是固定的,所以我的线程一直遇到问题,问题中也显示了这些错误


因为他们锁定了这个数量,我的选择受到限制,所以我决定切换提供程序。

我已经跟踪了我的bot使用的内存,主要是JDA,它只占用140MB的内存,这在堆空间中并没有那么多内存。我设法找到了我自己问题的答案,但这确实是一个有效的说法,您需要使用mavencentral升级到4.2.0_252,所以不要使用jcenter。谢谢你的帮助,明
[111,061s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
Exception in thread "Thread-365" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
        at java.base/java.lang.Thread.start0(Native Method)
        at java.base/java.lang.Thread.start(Thread.java:804)
        at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:937)
        at java.base/java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1583)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:346)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:705)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.applyAndAckSettings(Http2Connection.java:738)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.settings(Http2Connection.java:710)
        at okhttp3.internal.http2.Http2Reader.readSettings(Http2Reader.java:289)
        at okhttp3.internal.http2.Http2Reader.nextFrame(Http2Reader.java:141)
        at okhttp3.internal.http2.Http2Reader.readConnectionPreface(Http2Reader.java:80)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.execute(Http2Connection.java:607)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.base/java.lang.Thread.run(Thread.java:835)