首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何实现Red Hat Linux中的低Java单进程线程限制?

如何实现Red Hat Linux中的低Java单进程线程限制?
EN

Stack Overflow用户
提问于 2018-08-15 05:00:55
回答 2查看 0关注 0票数 0

我正在使用的线程测试的代码如下:

代码语言:javascript
复制
public class ThreadTest {

   public static void main(String[] pArgs) throws Exception {

      try {
         // keep spawning new threads forever
         while (true) {
            new TestThread().start();
         }
      }
      // when out of memory error is reached, print out the number of
      // successful threads spawned and exit
      catch ( OutOfMemoryError e ) {
         System.out.println(TestThread.CREATE_COUNT);
         System.exit(-1);
      }
   }

   static class TestThread extends Thread {
      private static int CREATE_COUNT = 0;
      public TestThread() {
         CREATE_COUNT++;
      }
      // make the thread wait for eternity after being spawned
      public void run() {
         try {
            sleep(Integer.MAX_VALUE);
         }
         // even if there is an interruption, dont do anything
         catch (InterruptedException e) {
         }
      }
   }
}
EN

回答 2

Stack Overflow用户

发布于 2018-08-15 13:31:38

应该能够运行线程限制来找到最大线程数,并且可以通过编译glibc来调整它

票数 0
EN

Stack Overflow用户

发布于 2018-08-15 14:31:17

用nptl线程将内核更新到更新版本(2.6左右)解决了这个问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档