简体   繁体   English

64位Centos Java JVM无法创建本机线程

[英]64 bit Centos Java JVM unable to create a native thread

I am using the Java Executor Service to create a singlethread. 我正在使用Java Executor服务创建单线程。 Code:- 码:-

ExecutorService executor = Executors.newSingleThreadExecutor();
try {
    executor.submit(new Runnable() {

        @Override
        public void run() {
            Iterator<FileObject> itr = mysortedList.iterator();
            while (itr.hasNext()) {
                myWebFunction(itr.next();
            }
        };
    }).get(Timeout * mysortedList.size() - 10, TimeUnit.SECONDS);
} catch (Exception ex) {

} finally {
    executor.shutdownNow();
}

Details : myWebfunction processes files of different size and content.Processing involves extracting the entire content and applying further actions on the file content. 详细信息myWebfunction处理大小和内容不同的文件content.Processing涉及提取整个内容,并对文件内容执行进一步的操作。 The program runs in 64bit Centos. 该程序在64位Centos中运行。

Problem : When the myWebfunction gets file of size greater than some threshold, say 10MB, the executor service is unable to create a native thread. 问题 :当myWebfunction获取的文件大小大于某个阈值(例如10MB)时,执行程序服务无法创建本机线程。 I tried various -Xmx and -Xms settings, but still the executor service throws the same error. 我尝试了各种-Xmx-Xms设置,但是执行程序服务仍然抛出相同的错误。

My guess is you calling this many times, and you are not waiting for the thread which has timed out, leaving lots of threads lying around. 我的猜测是您多次调用此命令,而您不是在等待线程超时,而是留下大量线程。 When you run out of stack space, or you reach about 32K threads, you cannot create any more. 当堆栈空间用完或到达约32K线程时,将无法再创建任何线程。

I suggest using a different approach which doesn't use so many threads or kills them off when you know you don't need them any more. 我建议使用另一种方法,该方法不会使用太多线程或在您不再需要它们时将其杀死。 Eg have the while loop check for interrupts and call Future.cancel(true) to interrupt it. 例如,在while循环中检查中断,然后调用Future.cancel(true)来中断它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM