Hi, sorry I just saw this thread.
You're right FC.iterator() is awkward, and we're supposed to get rid of
it when someone finally gets the chance to dedicate the time to clean up
FeatureCollection as a whole.
So yeah, you always need to close the iterators. Remember to even do so
inside a finally block:
FeatureCollection fc = ....
FeatureIterator it = fc.features();
try{
do something
}finally{
it.close();
}
Cheers,
Gabriel
On Fri, 2010-11-19 at 15:46 +0100, Schuster Stefan wrote:
> Hi,
>
>
>
> finally I found the problem, it was the following line that is not
> allowed:
>
>
>
> SimpleFeature adresse = fc.iterator().next();
>
>
>
> As FeatureCollaction provides the method Iterator<F> iterator() I assumed it
> behaves like java.lang.Iterable, but it does NOT !
>
> Of course I have to acknowledge that this issue is well documented in the
> JavaDoc of FeatureCollection, but I still think the name of the iterator()
> method should be reconsidered, as it makes this misunderstanding more likely.
>
> For the sake of completeness here the correct replacement of the wrong line:
>
>
> Iterator<SimpleFeature> sfit = fc.iterator();
>
> SimpleFeature adresse = sfit.next();
>
> fc.close(sfit);
>
>
>
>
>
> Stefan
>
>
> ______________________________________________________________________
> Von: Schuster Stefan [mailto:[email protected]]
> Gesendet: Freitag, 19. November 2010 11:27
> An: [email protected]
> Betreff: [Geotools-gt2-users] ArcSDEDataStore Session pool exhausted
>
>
>
>
> Hi,
>
>
>
> I’m using geotools to connect to an ArcSDE Database. I reuse a single
> instance of the Datastore created by the corresponding factory:
>
>
>
> ArcSDEDataStoreFactory factory = new ArcSDEDataStoreFactory();
>
> DataStore store = factory.createDataStore(params);
>
>
>
> Later I use this store to read data like in this debug method:
>
>
>
> private void debug(DataStore store) throws IOException, CQLException {
>
> String strassenkennziffer = "3162";
>
> String hausnummer = "150";
>
>
>
> FeatureSource<SimpleFeatureType, SimpleFeature> s = store
>
> .getFeatureSource("GIS.ADDRESS");
>
> Filter filter = CQL.toFilter("STRASSENKENNZIFFER == '"
>
> + strassenkennziffer + "' AND HAUSNUMMER == '" +
> hausnummer
>
> + "'");
>
> FeatureCollection<SimpleFeatureType, SimpleFeature> fc = s
>
> .getFeatures(filter);
>
>
>
> if (fc.size() != 1) {
>
> log("Not exactly one address found");
>
> return;
>
> }
>
> SimpleFeature adresse = fc.iterator().next();
>
> Object oAref = adresse.getDefaultGeometry();
>
> if (!(oAref instanceof Point)) {
>
> log("adrdess is not a point");
>
> return;
>
> }
>
> Point adressPoint = (Point) oAref;
>
> log("Coordinates of adress: X:" + adressPoint.getX() + " Y:"
>
> + adressPoint.getY());
>
> }
>
>
>
>
>
> This works fine, but only for 6 successive calls of the debug method,
> in the 7th call I receive the following exception:
>
>
>
> 19.11.2010 11:22:05 org.geotools.arcsde.session.SessionPool getSession
>
> WARNUNG: Out of connections: Timeout waiting for idle object. Config:
> ArcSDEConnectionConfig[server=nyx, port=5151, database=null, user=sde,
> minConnections=2, maxConnections=6, timeout=500]
>
> java.lang.RuntimeException: Session pool exhausted
>
> at
> org.geotools.arcsde.data.ArcSDEDataStore.getSession(ArcSDEDataStore.java:179)
>
> at
> org.geotools.arcsde.data.ArcSdeFeatureSource.getSession(ArcSdeFeatureSource.java:248)
>
> at
> org.geotools.arcsde.data.ArcSdeFeatureSource.getCount(ArcSdeFeatureSource.java:215)
>
> at
> org.geotools.arcsde.data.ArcSdeFeatureCollection.getCount(ArcSdeFeatureCollection.java:104)
>
> at
> org.geotools.data.store.DataFeatureCollection.size(DataFeatureCollection.java:265)
>
> at
> de.gevas.geotools.konverter.feuerwehr.TestGui.debug(TestGui.java:302)
>
>
>
>
>
>
> Do I have to release something?
>
>
>
> Tanks for help!
>
>
>
> Stefan
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
> Spend less time writing and rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________ Geotools-gt2-users mailing
> list [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
--
Gabriel Roldan
[email protected]
Expert service straight from the developers
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users