&quot“ java.lang.outofmemoryerror:无法创建本机线程:可能无法到达内存或进程/资源限制。如果程序由Cron发起
我有一个Java程序,当我通过普通的shell命令(Java -jar xxx.jar)启动时,我的Unix Web服务器运行
很好
[0.075s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
Exception in thread "main" 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:801)
完全 似乎不是Java编码错误,因为它似乎在开始外壳时没有任何问题。由于其他Java程序的执行正常,因此CRON似乎也不是错误。
我读到Cron的系统资源有限。因此,我检查了系统中的用户限制:
$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1545091
max locked memory (kbytes, -l) 65536
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 62987
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
然后我调整了cron的SystemD:
$ systemctl stop cron
$ sudo systemctl edit cron
$ systemctl daemon-reload
$ systemctl start cron
在“ SystemCtl Edit Cron”文件中,我试图复制Ulimit值 (映射在 https://unix.stackexchange.com/问题/345595/how-to-stet-ulimits-on-service-with-systemd )
TasksMax=unlimited
LimitCORE=unlimited
LimitDATA=unlimited
LimitFSIZE=unlimited
LimitSIGPENDING=1545091
LimitMEMLOCK=65536
LimitRSS=unlimited
LimitNOFILE=1024
LimitSTACK=unlimited
LimitCPU=unlimited
LimitNPROC=62987
LimitAS=unlimited
LimitLOCKS=unlimited
但是,这一切都无济于事,当克朗试图启动程序时的错误仍然相同。
由于我在这里完全没有智慧,因此欢迎任何建议。
I have a java program that runs totally fine on my UNIX webserver when I start it through a normal shell command (java -jar xxx.jar)
However, I am trying a scheduled run through cron and receive the following error:
[0.075s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
Exception in thread "main" 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:801)
As said, it does not seem to be a java coding error since it seems to be running without any problems when started to shell. Nor it seems to be an error with cron since other java programs are being executed fine.
I read that the system resources for cron are limited. So I checked the user limits in the system:
$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1545091
max locked memory (kbytes, -l) 65536
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 62987
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
And then I adjusted the systemd for cron:
$ systemctl stop cron
$ sudo systemctl edit cron
$ systemctl daemon-reload
$ systemctl start cron
And, in the file for "systemctl edit cron" I tried to replicate the ulimit values
(mapping found at https://unix.stackexchange.com/questions/345595/how-to-set-ulimits-on-service-with-systemd)
TasksMax=unlimited
LimitCORE=unlimited
LimitDATA=unlimited
LimitFSIZE=unlimited
LimitSIGPENDING=1545091
LimitMEMLOCK=65536
LimitRSS=unlimited
LimitNOFILE=1024
LimitSTACK=unlimited
LimitCPU=unlimited
LimitNPROC=62987
LimitAS=unlimited
LimitLOCKS=unlimited
However, this all didn't help much, the error when cron tries to start the program is still the same.
Since I am totally out of my wits here, any suggestions would be welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,经过进一步的研究,我发现必须更改整个系统以及CRON服务的“ DefaultMaxtasks”。该值设置为195,它太低了。
有用的链接是:
https://www.suse.com/supe.com/support/support/kb/kb/doc//doc/? id = 000015901
https://docs.oracle.com/en/database/oracle/oracle/oracle/oracle-database/19/ladbi/configuring-configuring-defaulttasksmax-for-suse.html-suse.html#guid-guid-0815d18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18dd18d-d18dd18dd18d-d18d-d18d-d18d-dd18d-d18d-dd18dd-65e7-46b2- BA89-F54BA02EFCB8
更改整个defaultTasksmax:
cron的更改值:
在Override.conf中,我设置了新值。 DefaultTaskSmax:
检查显示设置设置该值也是新设置的cron:
之后,解决了问题
So, after some further research I found out that the "DefaultMaxTasks" had to be changed for the overall system as well as for the cron service. The value was set to 195 which was too low.
Helpful links were:
https://www.suse.com/support/kb/doc/?id=000015901
https://docs.oracle.com/en/database/oracle/oracle-database/19/ladbi/configuring-defaulttasksmax-for-suse.html#GUID-0815D18D-65E7-46B2-BA89-F54BA02EFCB8
change the overall DefaultTasksMax:
change values for cron:
in the override.conf, I set the new values incl. DefaultTasksMax:
and the check shows set the value is also newly set for cron:
After that, the problem was resolved