1

私は5秒ごとに新しいスレッドを作成しており、Threadpool exector.スレッドが閉じられていることを確認しています。しかし、私は得ています

Exception in thread "Timer-0" java.lang.OutOfMemoryError: unable to create new native thread.

多くのスレッドを作成して閉じていないために発生していますか? または頻繁に新しいものを作成しますか?

コードで何か間違ったことをしている場合、誰か教えてもらえますか?

public class API{
    private   MongoStoreExecutor executor = new MongoStoreExecutor(10,50);
    private class MongoStoreExecutor extends ThreadPoolExecutor {
        public MongoStoreExecutor(int queueSize, int maxThreadPoolSize) {
            super(10, maxThreadPoolSize, 30, TimeUnit.SECONDS, 
                new ArrayBlockingQueue<Runnable>(queueSize),
                new ThreadPoolExecutor.CallerRunsPolicy());
        }
    }

    public TimerTask alertingPoolsData() throws Exception, UnknownHostException {
        TimeerTask task  = new TimerTask(){
            public void run(){
                Pools = alertingPools.values().toArray();
                List<Future<?>> tasks = new ArrayList<Future<?>>(Pools.length);
                for (Object pool : Pools) {
                    tasks.add(executor.submit(new DataAccumulation(timeStartSecData,
                        timeEndSec,pool, jsonArrayResult,dataResult)));
                }
                for( Future<?> f: tasks) {
                    f.get(2 * 1000L, TimeUnit.MILLISECONDS);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        long interval = 5 * 1000L;
        tm.scheduleAtFixedRate(task,(interval - 
            (System.currentTimeMillis() % interval)), interval);
        return task;
    }
}
4

1 に答える 1