java. Lang. outofmemoryerror: cannot create a new native thread

I see such comments

At Sun Java Forums

In my application, we initially planned to use threads, but then we decided we didn't need them anymore, so we only called run () instead of start () Do we need to create a new threadclass (..) Do manual GC?

My Tomcat startup settings

-Xms1024m -Xmx1024m -XX:MaxPermSize=450m

Solution

Why create a thread first?

Your code should implement the runnable interface

Then, when you decide to run it in a thread, simply instantiate a thread with runnable as a parameter and call start () on the thread object

Conversely, if you just want to run it in the current thread, just call run () on the runnable object

This has several benefits:

>As long as you don't care about individual threads, you won't involve any thread Objects > your code is wrapped in a runnable, which is closer in concept: you're not writing some special threads, are you? You just need to write some code that can be executed / run. > You can easily switch to using executor to further Abstract decisions

Last but not least, you avoid any possible confusion about whether to create native thread resources

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>