Skip to content

SocketConnectionPool

VictorZeng edited this page May 12, 2016 · 3 revisions

Use the SocketConnectionPool need instantiate PoolConfig and Properties

For example, the following

		/* poolConfig */
		PoolConfig config = new PoolConfig();
		config.setMaxTotal(20);
		config.setMaxIdle(5);
		config.setMaxWaitMillis(1000);
		config.setTestOnBorrow(true);

		/* properties */
		Properties props = new Properties();
		props.setProperty("address", "localhost:1234");
		props.setProperty("receiveBufferSize", "3072");
		props.setProperty("sendBufferSize", "3072");
		props.setProperty("connectionTimeout", "2000");
		props.setProperty("soTimeout", "2000");

		/* connection pool */
		SocketConnectionPool pool = new SocketConnectionPool(config, props);

		/* pool getConnection */
		Socket socket = pool.getConnection();

		...

		/* pool returnConnection */
		pool.returnConnection(socket);

More configs see the Configuration wiki.