java.lang.OutOfMemoryError: Java heap space

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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)
    via by hiyoucai,
  • 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)
    via by hiyoucai,
    • 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)
    No Bugmate found.