title: When are connections taken/returned from a connection pool?
body: <p>I have a simple Java SE Application which uses JPA(EclipseLink). By default I have <a href="http://www.eclipse.org/eclipselink/api/2.4/org/eclipse/persistence/config/PersistenceUnitProperties.html#CONNECTION_POOL" rel="nofollow">one 'default' connection pool</a> which allows up to <a href="http://www.eclipse.org/eclipselink/api/2.4/org/eclipse/persistence/config/PersistenceUnitProperties.html#CONNECTION_POOL_MAX" rel="nofollow">32 connections</a>.</p>
  
  <p>Suppose I do something like this:</p>
  
  <pre><code>EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("myPU");
  
  //read
  EntityManager em = emFactory.createEntityManager();
  
  TypedQuery&lt;Entity.class&gt; q = em.createQuery("Select e from Entity e", Entity.class);
  List&lt;Entity&gt; entities = q.getResultList();
  
  em.close();
  
  //write
  em = emFactory.createEntityManager();
  
  Entity e = new Entity();
  em.getTransaction().begin();
  em.persist(e);
  em.getTransaction().commit();
  
  em.close();
  </code></pre>
  
  <ul>
  <li>When are connections actually requested from the connection pool and when are they released again?</li>
  <li>Can one query request multiple connections from the pool?</li>
  <li>Would there be a difference if I set the maximum number of connections from 32 to 1?</li>
  </ul>