Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private BlockingQueue<Connection> pool = new LinkedBlockingQueue<Connection>(10);
- private AtomicInteger connCount = new AtomicInteger();
- public Connection getConnection() {
- Connection conn = pool.poll(10, TimeUnit.MILLISECONDS);
- if (conn == null) {
- synchronized (connCount) {
- if (connCount.get() < 10) {
- conn = getNewConnection();
- pool.offer(conn);
- connCount.incrementAndGet();
- }
- }
- conn = pool.take();
- }
- return conn;
- }
Add Comment
Please, Sign In to add comment