Support Questions
Find answers, ask questions, and share your expertise

HBase, Phoneix, Spring boot, JDBCTemplate, The connection failed when sending a large array

HBase, Phoneix, Spring boot, JDBCTemplate, The connection failed when sending a large array

Explorer

Hi All,

I have a spring boot application and connect to Phoneix HBase.

i have a post function like:

@RequestMapping(method = RequestMethod.POST, value = "data/batchinsert/")
	public ResponseEntity<?> batchInsertHaEnvrironmentData(@RequestBody List<HaEnvrironmentData> tts) {
		int i = heds.batchInsert(tts);
		if (i <= 0)
			new ResponseEntity<String>("failed", HttpStatus.NO_CONTENT);
		return new ResponseEntity<String>("Successed", HttpStatus.OK);
	}

TheDao:

public int batchInsert(List<HaEnvrironmentData> eds){
		String sql=EvotionSqlUtils.getUpsertSql("HA_ENVRIRONMENT_DATA", true, HaEnvrironmentEnum.class, null);
		BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() {
			@Override
			public void setValues(PreparedStatement ps, int i) throws SQLException {
				HaEnvrironmentData ed=eds.get(i);
				Connection conn= getConnection();
				ps.setString(1,  ed.getId());
				ps.setTimestamp(2,  ed.getRecord_date());
				ps.setString(3,  ed.getAid_id());
				ps.setShort(4, ed.getEnvironment_classification_unit());
				
			}
			@Override
		    public int getBatchSize() {
		        return eds.size();
		    }
		  };
		  int[] counts=jdbcTemplate.batchUpdate(sql, bpss);
		  return counts.length;
	}

The data list

[

{"id":"EX2017000021",
"record_date":1515747937238,"type":2,
"aid_id":"82E3735E",
"environment_classification_unit":0},

....
]

This works fine with two or three data in the list. However, it failed when I am trying with 100 data blocks on the list.

And shows the error below:

org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-nio-8080-exec-2] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000].
	at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:706)
	at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:198)
	at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:132)
	at org.evotion.datarepository.dao.BaseDaoImpl.getConnection(BaseDaoImpl.java:115)
	at org.evotion.datarepository.dao.HaEnvrironmentDataDaoImpl.insert(HaEnvrironmentDataDaoImpl.java:43)
	at org.evotion.datarepository.dao.HaEnvrironmentDataDaoImpl.batchInsert(HaEnvrironmentDataDaoImpl.java:55)
	at org.evotion.datarepository.dao.HaEnvrironmentDataDaoImpl$$FastClassBySpringCGLIB$$618b5314.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

By the way, the JDBCTemplate will release the connection automatically. but why every time, when I execute the post function above, the connection pool gets exhausted.

Please help me!

Many thanks in advance.

2 REPLIES 2

Re: HBase, Phoneix, Spring boot, JDBCTemplate, The connection failed when sending a large array

Super Collaborator

I would suggest disabling connection pooling first. FAQ

Re: HBase, Phoneix, Spring boot, JDBCTemplate, The connection failed when sending a large array

Explorer

How to disable the connection pool?