java.lang.OutOfMemoryError: Java heap space

Spring JIRA | hiyoucai | 4 years ago
  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 | 4 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 | 4 years ago | hiyoucai
    java.lang.OutOfMemoryError: Java heap space
  3. 0

    OutOfMemory Exception : java heap space

    Google Groups | 6 months ago | deepak singh
    java.lang.OutOfMemoryError: Java heap space* *java.lang.OutOfMemoryError: Java heap space*
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    OutOfMemory Exception : java heap space

    Google Groups | 6 months ago | deepak singh
    java.lang.OutOfMemoryError: Java heap space* *java.lang.OutOfMemoryError: Java heap space*
  6. 0

    [exoplatform] [explatform] Memory requirements

    ow2.org | 1 year ago
    java.lang.OutOfMemoryError: Java heap space>java.lang.OutOfMemoryError: Java heap space

    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

      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