java.lang.OutOfMemoryError: Java heap space

Spring JIRA | hiyoucai | 5 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    The following is the same function code that write by two different style. Code A is run perfect but code B is throw an exception. I know the code A is a good style, but How to avoid such problems. Because not everyone is a good programmer. 【code A】 ------------------------------------------------------------------ RedisTemplate<String, List<Student>> a = getRedisTemplate(); ValueOperations<String, List<Student>> b = a.opsForValue(); for (int i = 0; i < 10000; i++) { try{ List<Student> c = b.get("a"); System.out.println((ii++) + " : " + c); //a.discard(); }catch (Exception e) { e.printStackTrace(); } } ------------------------------------------------------------------ 【code B】 ------------------------------------------------------------------ for (int i = 0; i < 10000; i++) { try{ RedisTemplate<String, List<Student>> a = getRedisTemplate(); ValueOperations<String, List<Student>> b = a.opsForValue(); List<Student> c = b.get("a"); System.out.println((ii++) + " : " + c); //a.discard(); }catch (Exception e) { e.printStackTrace(); } } ------------------------------------------------------------------ 【throw exception info:】 ------------------------------------------------------------------ Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:36) at redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:40) at redis.clients.jedis.Connection.connect(Connection.java:132) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:69) at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1665) at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:72) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1158) at redis.clients.util.Pool.getResource(Pool.java:20) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:94) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:148) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:41) at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:81) at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:53) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:150) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:133) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84) at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:42) at travel_redis.RedisEngine.main(RedisEngine.java:67)

    Spring JIRA | 5 years ago | hiyoucai
    java.lang.OutOfMemoryError: Java heap space
  2. 0

    The following is the same function code that write by two different style. Code A is run perfect but code B is throw an exception. I know the code A is a good style, but How to avoid such problems. Because not everyone is a good programmer. 【code A】 ------------------------------------------------------------------ RedisTemplate<String, List<Student>> a = getRedisTemplate(); ValueOperations<String, List<Student>> b = a.opsForValue(); for (int i = 0; i < 10000; i++) { try{ List<Student> c = b.get("a"); System.out.println((ii++) + " : " + c); //a.discard(); }catch (Exception e) { e.printStackTrace(); } } ------------------------------------------------------------------ 【code B】 ------------------------------------------------------------------ for (int i = 0; i < 10000; i++) { try{ RedisTemplate<String, List<Student>> a = getRedisTemplate(); ValueOperations<String, List<Student>> b = a.opsForValue(); List<Student> c = b.get("a"); System.out.println((ii++) + " : " + c); //a.discard(); }catch (Exception e) { e.printStackTrace(); } } ------------------------------------------------------------------ 【throw exception info:】 ------------------------------------------------------------------ Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:36) at redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:40) at redis.clients.jedis.Connection.connect(Connection.java:132) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:69) at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1665) at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:72) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1158) at redis.clients.util.Pool.getResource(Pool.java:20) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:94) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:148) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:41) at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:81) at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:53) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:150) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:133) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84) at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:42) at travel_redis.RedisEngine.main(RedisEngine.java:67)

    Spring JIRA | 5 years ago | hiyoucai
    java.lang.OutOfMemoryError: Java heap space

    Root Cause Analysis

    1. java.lang.OutOfMemoryError

      Java heap space

      at redis.clients.util.RedisInputStream.<init>()
    2. Jedis
      JedisPool$JedisFactory.makeObject
      1. redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:36)
      2. redis.clients.util.RedisInputStream.<init>(RedisInputStream.java:40)
      3. redis.clients.jedis.Connection.connect(Connection.java:132)
      4. redis.clients.jedis.BinaryClient.connect(BinaryClient.java:69)
      5. redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1665)
      6. redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:72)
      6 frames
    3. Commons Pool
      GenericObjectPool.borrowObject
      1. org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1158)
      1 frame
    4. Jedis
      Pool.getResource
      1. redis.clients.util.Pool.getResource(Pool.java:20)
      1 frame
    5. Spring Data Redis
      DefaultValueOperations.get
      1. org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:94)
      2. org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:148)
      3. org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:41)
      4. org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:81)
      5. org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:53)
      6. org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:150)
      7. org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:133)
      8. org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84)
      9. org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:42)
      9 frames
    6. travel_redis
      RedisEngine.main
      1. travel_redis.RedisEngine.main(RedisEngine.java:67)
      1 frame