Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

At runtime, how can I limit the number of java threads

I am running a genome assembly program *Trinity, http://trinityrnaseq.sourceforge.net/, if interested) on one of the XSEDE resources. The hardware limits the number of threads to 2500, which the program always wants to exceed... It there an easy way to limit the number of threads executed? I have tried -XX:ParallelGCThreads=16, but this seems to introduce new errors.

So, is there a runtime command to limit the total number of threads??

like image 821
Matt MacManes Avatar asked Dec 09 '11 17:12

Matt MacManes


People also ask

How many threads can run at a time in Java?

Each JVM server can have a maximum of 256 threads to run Java applications. In a CICS region you can have a maximum of 2000 threads. If you have many JVM servers running in the CICS region (for example, more than seven), you cannot set the maximum value for every JVM server.

How do you stop an infinite thread in Java?

You cannot. There is no way to stop a Thread unless it co-operates.

Can we stop a running thread in Java?

Whenever we want to stop a thread from running state by calling stop() method of Thread class in Java. This method stops the execution of a running thread and removes it from the waiting threads pool and garbage collected. A thread will also move to the dead state automatically when it reaches the end of its method.

How do you manage threads in Java?

Every Java program contains at least one thread: the main thread. Additional threads are created through the Thread constructor or by instantiating classes that extend the Thread class. Java threads can create other threads by instantiating a Thread object directly or an object that extends Thread .


1 Answers

Use an Executor or ExecutorService. Does what bragboy suggests but it's built in to Java.

like image 117
user949300 Avatar answered Sep 26 '22 02:09

user949300