java.lang.OutOfMemoryError: unable to create new native thread

Spring JIRA | Roland | 1 year ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    java.lang.OutOfMemoryError: unable to create new native thread

    GitHub | 1 year ago | rolandgroen
    java.lang.OutOfMemoryError: unable to create new native thread
  2. 0

    The RedisMessageListenerContainer uses the SimpleAsyncTaskExecutor, the SimpleAsyncTaskExecutor creates a new, short lived, thread for every message. This causes out of memory errors on our production environment. The spring-data-redis version is 1.3.6-RELEASE, however the latest version (1.7.1) still uses the SimpleAsyncTaskExecutor. The report is below: After about 3 or 4 days of usage (300 concurrent users) our application stopped responding, and the log shows an "java.lang.OutOfMemoryError: unable to create new native thread" error. The default implementation of the RedisMessageListenerContainer uses a SimpleAsyncTaskExecutor that creates a thread on every call to dispatchMessage. This somehow repletes the available threads. The JDK version is 1.7.0_79-b15, 64-Bit. See also: https://plumbr.eu/outofmemoryerror/unable-to-create-new-native-thread The solution is quite simple, make use of one of the java.util.concurrent.Executors to dispatch the message. The stack is: {code} 2016-04-01 08:46:47,507 [redisMessageListenerContainer-1] ERROR org.springframework.data.redis.listener.RedisMessageListenerContainer - SubscriptionTask aborted with exception: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at org.springframework.core.task.SimpleAsyncTaskExecutor.doExecute(SimpleAsyncTaskExecutor.java:192) at org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:166) at org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:147) at org.springframework.data.redis.listener.RedisMessageListenerContainer.dispatchMessage(RedisMessageListenerContainer.java:948) at org.springframework.data.redis.listener.RedisMessageListenerContainer.access$1400(RedisMessageListenerContainer.java:61) at org.springframework.data.redis.listener.RedisMessageListenerContainer$DispatchMessageListener.onMessage(RedisMessageListenerContainer.java:939) at org.springframework.data.redis.connection.jedis.JedisMessageListener.onPMessage(JedisMessageListener.java:43) at redis.clients.jedis.BinaryJedisPubSub.process(BinaryJedisPubSub.java:102) at redis.clients.jedis.BinaryJedisPubSub.proceedWithPatterns(BinaryJedisPubSub.java:69) at redis.clients.jedis.BinaryJedis.psubscribe(BinaryJedis.java:3152) at org.springframework.data.redis.connection.jedis.JedisConnection.pSubscribe(JedisConnection.java:2681) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.eventuallyPerformSubscription(RedisMessageListenerContainer.java:763) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.run(RedisMessageListenerContainer.java:730) at java.lang.Thread.run(Thread.java:745) {code}

    Spring JIRA | 1 year ago | Roland
    java.lang.OutOfMemoryError: unable to create new native thread
  3. 0

    The RedisMessageListenerContainer uses the SimpleAsyncTaskExecutor, the SimpleAsyncTaskExecutor creates a new, short lived, thread for every message. This causes out of memory errors on our production environment. The spring-data-redis version is 1.3.6-RELEASE, however the latest version (1.7.1) still uses the SimpleAsyncTaskExecutor. The report is below: After about 3 or 4 days of usage (300 concurrent users) our application stopped responding, and the log shows an "java.lang.OutOfMemoryError: unable to create new native thread" error. The default implementation of the RedisMessageListenerContainer uses a SimpleAsyncTaskExecutor that creates a thread on every call to dispatchMessage. This somehow repletes the available threads. The JDK version is 1.7.0_79-b15, 64-Bit. See also: https://plumbr.eu/outofmemoryerror/unable-to-create-new-native-thread The solution is quite simple, make use of one of the java.util.concurrent.Executors to dispatch the message. The stack is: {code} 2016-04-01 08:46:47,507 [redisMessageListenerContainer-1] ERROR org.springframework.data.redis.listener.RedisMessageListenerContainer - SubscriptionTask aborted with exception: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at org.springframework.core.task.SimpleAsyncTaskExecutor.doExecute(SimpleAsyncTaskExecutor.java:192) at org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:166) at org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:147) at org.springframework.data.redis.listener.RedisMessageListenerContainer.dispatchMessage(RedisMessageListenerContainer.java:948) at org.springframework.data.redis.listener.RedisMessageListenerContainer.access$1400(RedisMessageListenerContainer.java:61) at org.springframework.data.redis.listener.RedisMessageListenerContainer$DispatchMessageListener.onMessage(RedisMessageListenerContainer.java:939) at org.springframework.data.redis.connection.jedis.JedisMessageListener.onPMessage(JedisMessageListener.java:43) at redis.clients.jedis.BinaryJedisPubSub.process(BinaryJedisPubSub.java:102) at redis.clients.jedis.BinaryJedisPubSub.proceedWithPatterns(BinaryJedisPubSub.java:69) at redis.clients.jedis.BinaryJedis.psubscribe(BinaryJedis.java:3152) at org.springframework.data.redis.connection.jedis.JedisConnection.pSubscribe(JedisConnection.java:2681) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.eventuallyPerformSubscription(RedisMessageListenerContainer.java:763) at org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.run(RedisMessageListenerContainer.java:730) at java.lang.Thread.run(Thread.java:745) {code}

    Spring JIRA | 1 year ago | Roland
    java.lang.OutOfMemoryError: unable to create new native thread
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    netbout failed with OutOfMemoryError

    GitHub | 2 years ago | alevohin
    java.lang.OutOfMemoryError: unable to create new native thread
  6. 0

    GitHub comment 96#162611775

    GitHub | 1 year ago | Metal-Mighty
    java.lang.OutOfMemoryError: unable to create new native thread

  1. nasimk 1 times, last 6 days ago
  2. poroszd 530 times, last 2 months ago
  3. Reich 4 times, last 6 months ago
  4. Ajeet 46 times, last 9 months ago
  5. Diogo Jaym 1 times, last 11 months ago
3 more registered users
30 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.OutOfMemoryError

    unable to create new native thread

    at java.lang.Thread.start0()
  2. Java RT
    Thread.start
    1. java.lang.Thread.start0(Native Method)
    2. java.lang.Thread.start(Thread.java:714)
    2 frames
  3. Spring Core
    SimpleAsyncTaskExecutor.execute
    1. org.springframework.core.task.SimpleAsyncTaskExecutor.doExecute(SimpleAsyncTaskExecutor.java:192)
    2. org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:166)
    3. org.springframework.core.task.SimpleAsyncTaskExecutor.execute(SimpleAsyncTaskExecutor.java:147)
    3 frames
  4. Spring Data Redis
    JedisMessageListener.onPMessage
    1. org.springframework.data.redis.listener.RedisMessageListenerContainer.dispatchMessage(RedisMessageListenerContainer.java:948)
    2. org.springframework.data.redis.listener.RedisMessageListenerContainer.access$1400(RedisMessageListenerContainer.java:61)
    3. org.springframework.data.redis.listener.RedisMessageListenerContainer$DispatchMessageListener.onMessage(RedisMessageListenerContainer.java:939)
    4. org.springframework.data.redis.connection.jedis.JedisMessageListener.onPMessage(JedisMessageListener.java:43)
    4 frames
  5. Jedis
    BinaryJedis.psubscribe
    1. redis.clients.jedis.BinaryJedisPubSub.process(BinaryJedisPubSub.java:102)
    2. redis.clients.jedis.BinaryJedisPubSub.proceedWithPatterns(BinaryJedisPubSub.java:69)
    3. redis.clients.jedis.BinaryJedis.psubscribe(BinaryJedis.java:3152)
    3 frames
  6. Spring Data Redis
    RedisMessageListenerContainer$SubscriptionTask.run
    1. org.springframework.data.redis.connection.jedis.JedisConnection.pSubscribe(JedisConnection.java:2681)
    2. org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.eventuallyPerformSubscription(RedisMessageListenerContainer.java:763)
    3. org.springframework.data.redis.listener.RedisMessageListenerContainer$SubscriptionTask.run(RedisMessageListenerContainer.java:730)
    3 frames
  7. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:745)
    1 frame