I should also mention that if I include the max connections directive and
also add "Connection timeout" to 2 or 3 seconds, the program hangs only for
that amount of time and then an exception is thrown
that the underlying dataSource could not fetch a connection because it was
waiting too long for idle objects.

On Fri, Dec 30, 2011 at 6:15 PM, Alessandro Ferrucci <
[email protected]> wrote:

> Hello,
>
> I am running into an issue where a PostGIS datastore in geotools 2.7-RC2
> does not seem to be releasing connections back to the server upon
> FeatureReader.close(). if a DefaultTransaction is involved and I do not
> understand why.
>
> I have a very small test where I configured my postgres server with
> max_connections to 1.  Then I wrote a small test program to loop 10 times
> and just fetch 1 feature each time.
>
> the part I can't figure out is that if I remove the transaction from the
> getFeatureReader call and just pass in NULL, it works fine and the program
> terminates OK.
>
> If instead I pass the transaction in (and I don't have the line
> params.put("max connections", 1); ) the program crashes with:
>
> java.lang.RuntimeException: Unable to obtain connection: FATAL: sorry, too
> many clients already
>     at
> org.geotools.jdbc.JDBCDataStore.createConnection(JDBCDataStore.java:1566)
>     at
> org.geotools.jdbc.JDBCDataStore.getConnection(JDBCDataStore.java:1528)
>     at
> org.geotools.jdbc.JDBCDataStore.getConnection(JDBCDataStore.java:1545)
>     at
> org.geotools.jdbc.JDBCFeatureSource.getReaderInternal(JDBCFeatureSource.java:537)
>     at
> org.geotools.jdbc.JDBCFeatureStore.getReaderInternal(JDBCFeatureStore.java:209)
>     at
> org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.java:483)
>     at
> org.geotools.data.store.ContentDataStore.getFeatureReader(ContentDataStore.java:414)
>     at Main2.main(Main2.java:57)
> Caused by: org.postgresql.util.PSQLException: FATAL: sorry, too many
> clients already
>     at
> org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:291)
>     at
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
>     at
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>     at
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
>     at
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>     at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>     at org.postgresql.Driver.makeConnection(Driver.java:393)
>     at org.postgresql.Driver.connect(Driver.java:267)
>     at
> org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
>
>
> However, if I do use transaction and include the line params.put("max
> connections", 1);
>
> The program hangs on the second iteration right at: featureReader =
> datastore.getFeatureReader(q, transaction);
>
> Below is the class I'm referring to, Any help would be appreciated as to
> why not using the transaction seems to cause connections to be truly
> released by the DataStore (or the underlying Connection Pool).  Is there
> any way that Transactions can be kept in there and the "max connections"
> directive to be followed such that the program doesn't hang or run out of
> connections?
>
> public class Main2
> {
>
>     public static void main(String[] args)
>     {
>         Map params = new HashMap();
>         params.put("dbtype", "postgis");             //must be postgis
>         params.put("host", "myhost");        //the name or ip address of
> the machine running PostGIS
>         params.put("port", new Integer(5432));        //the port that
> PostGIS is running on (generally 5432)
>         params.put("database", "spatial");        //the name of the
> database to connect to.
>         params.put("user", "dbuser");                 //the user to
> connect with
>         params.put("passwd", "dbuser");               //the password of
> the user.
>         params.put("max connections", 1);
>         DataStore datastore = null;
>         try
>         {
>             datastore = DataStoreFinder.getDataStore(params);
>             FeatureReader<SimpleFeatureType, SimpleFeature> featureReader
> = null;
>             String[] columns = new String[]
>             {
>                 "the_geom", "colblkst",
>                 "colblkcou", "colblk"
>             };
>             for (int x = 0; x < 10; x++)
>             {
>                 try
>                 {
>                     System.out.println("going once!");
>
>                     String filterstr = "colblkst='01' and colblkcou='001'
> and colblk='10163'";
>                     Filter filter = CQL.toFilter(filterstr);
>                     Transaction transaction = new DefaultTransaction();
>                     DefaultQuery q = new DefaultQuery("collection_blocks",
> filter, columns);
>                     featureReader = datastore.getFeatureReader(q,
> transaction /*null*/);
>                     if (featureReader.hasNext())
>                     {
>                         SimpleFeature f = featureReader.next();
>                     }
>                     transaction.commit();
>                     featureReader.close();
>                  //   Thread.sleep(100000);
>                 }
>                 catch (Exception ex)
>                 {
>                     ex.printStackTrace();
>                 }
>             }
>         }
>         catch (IOException ex)
>         {
>             ex.printStackTrace();
>             System.exit(-1);
>         }
>     }
> }
>
> --
> Signed,
> Alessandro Ferrucci
>



-- 
Signed,
Alessandro Ferrucci
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to