ExecutorService and OutOfMemoryError: unable to create new native thread while using Executor

ExecutorService and OutOfMemoryError: unable to create new native thread while using Executor

Content Index :

ExecutorService and OutOfMemoryError: unable to create new native thread while using Executor
Tag : java , By : user92243
Date : November 28 2020, 11:01 PM

this will help My suggestion is to create only one thread pool. Thread pool is meant to manage your threads. If you are creating a thread pool everytime a method is called, then basically it is just as worse as creating thread everytime you are calling a method, but if you still insisted to create more than one thread pool then why don't you try this instead
private List< ListRow > fetchListRows( AmtRoomMachinesListModel amtRoomMachinesListModel )
   ExecutorService executor = Executors.newFixedThreadPool(20);
List< ListRow > listRows = Collections.synchronizedList( new ArrayList< ListRow >() );

for ( Machine machine : room.getRoomPCs() )
    executor.submit( new AmtcWorker( listRows, machine, amtRoomMachinesListModel ) );


    executor.awaitTermination( 20, TimeUnit.SECONDS );
catch ( InterruptedException e )
    throw new BootrobotException( ExceptionType.AMTC_ERROR, "command", "Waiting for thread termination", "error", e.getMessage() );


LOGGER.info( "Executor is shut down: " + executor.isShutdown() );
LOGGER.info( "Executor is terminated: " + executor.isTerminated() );

sortListRows( listRows );

return listRows;

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

ActiveMQ: outOfMemoryError: unable to create new native thread

Tag : rest , By : Brianna
Date : March 29 2020, 07:55 AM
may help you . The reason for this memory leak lies within activemq's connection handling. The default servlet creates one connection for each httpsession (which is a really bad idea). Me loadtesting tool doesn't care about sessions and doesn't send a session-id. So every message that was send is a new connection, is a new thread and after 17.000 threads the jvm is done.
Basicly I'm going to write a new servlet that uses one connection per worker thread. That should limmit the threadnumber to a bare minimum.

OutOfMemoryError: unable to create new native thread using ExecutorService

Tag : java , By : moss
Date : March 29 2020, 07:55 AM
With these it helps I'm not sure this is the only problem, but you are creating an ExecutorService in your checkState() method but you don't shut it down.
According to the JavaDocs for Executors.newFixedThreadPool():

OutOfMemoryError: unable to create new native thread while using Executor

Tag : java , By : kokok13
Date : March 29 2020, 07:55 AM
it helps some times Just to supply an answer for future readers:
The main idea of the solution is to initialize the ExecutorService instance only once and reuse it on each request (see comments above).
public class MySqlResource{

    private final ExecutorService executor;

    public MySqlResource() {
        this.executor = Executors.newFixedThreadPool(1);

    public Response insertOrUpdate(final String user) {

        try {
            new MYSQLProvider().insertOrUpdate(user);
            resulTObj.put("success", true);
            resulTObj.put("msg", "");

            executor.execute( new Runnable() {

                public void run() {
                    //...run() code goes here
        } catch (SQLException | JSONException e) {
            // TODO Auto-generated catch block
            resulTObj.put("success", false);
            resulTObj.put("msg", e.getMessage());

        return  Response.status(200).entity(resulTObj.toString()).build();
public class MySqlResource {

    //Note that the field is now static
    private static final ExecutorService executor;

    static {
        MySqlResource.executor = Executors.newFixedThreadPool(1);

    //Then the method can invoke it just as in the previous solution:
    public Response insertOrUpdate(final String user) {
        MySqlResource.executor.execute( new Runnable() {

                public void run() {
                    //...run() code goes here

Evaluation - OutOfMemoryError: unable to create new native thread

Tag : java , By : Francis
Date : March 29 2020, 07:55 AM
it helps some times
I wanted to know if there is an exact way to identify the root cause say the NOPROC has been exceeded etc

OutOfMemoryError: unable to create new native thread

Tag : java , By : user157654
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Is there a real benefit of using J#?
  • Why can't I use a try block around my super() call?
  • Accessing post variables using Java Servlets
  • Is this really widening vs autoboxing?
  • How can I Java webstart multiple, dependent, native libraries?
  • Why doesn't Java autoboxing extend to method invocations of methods of the autoboxed types?
  • How do I use Java to read from a file that is actively being written to?
  • What code analysis tools do you use for your Java projects?
  • IllegalArgumentException or NullPointerException for a null parameter?
  • How do I configure and communicate with a serial port?
  • What are the different methods to parse strings in Java?
  • Android Broadcastreceiver for other apps install/delete not working
  • Android Studio onClick not working in BindViewHolder
  • How to use Spring Converter for some controllers only?
  • How verify that 3 numbers in sequence are equals?
  • When using .compareTo to compare dates, why doesn't it take Months into account?
  • Does the perfomance of "filter then map" and "map then filter" differ in a Stream?
  • How can I set the initial Delay after pressing the start Button to a specific time (HH:mm:ss) format
  • How to switch between Android devices during the tests
  • How to configure java.util.logging via properties to use standard output?
  • How to iterate through array in order
  • Is there better way of iteration to find the evenly divisible number?
  • How do I avoid using if statements with a large amount of variables in java
  • Writing JUnit test cases for a Spring Boot Service Application with autowired components
  • Cors for GET with Postman not showing headers
  • Printing values in different column same row using APACHE POI
  • Fully decompile java6 web application
  • Passing keycloak configuration parameters in the code rather than reading from application.properties
  • setDataSource() IO exception
  • Unexpected Output while retrieving Data from mongodb and displaying in a csv file?
  • Algorithm for searching a value in two arrays
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com