Guest User

Untitled

a guest
Dec 12th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. private BlockingQueue<Connection> pool = new LinkedBlockingQueue<Connection>(10);
  2. private AtomicInteger connCount = new AtomicInteger();
  3.  
  4. public Connection getConnection() {
  5. Connection conn = pool.poll(10, TimeUnit.MILLISECONDS);
  6. if (conn == null) {
  7. synchronized (connCount) {
  8. if (connCount.get() < 10) {
  9. conn = getNewConnection();
  10. pool.offer(conn);
  11. connCount.incrementAndGet();
  12. }
  13. }
  14. conn = pool.take();
  15. }
  16.  
  17. return conn;
  18. }
Add Comment
Please, Sign In to add comment