Frank Gasdorf ha scritto:
> Hello,
>
> I got the following Exception thread if calling CRS.lookupEpsgCode in
> multible treads.
>
> Exception in thread "pool-2-thread-3"
> org.geotools.factory.RecursiveSearchException: Recursive call while creating
> a 'FactoryUsingWKT' object.
> at org.geotools.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:665)
> at org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:500)
> at org.geotools.factory.FactoryRegistry$1.filter(FactoryRegistry.java:191)
> at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:793)
> at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:811)
> at org.geotools.resources.LazySet.addNext(LazySet.java:70)
> at org.geotools.resources.LazySet.get(LazySet.java:120)
> at org.geotools.resources.LazySet$Iter.next(LazySet.java:139)
> at org.geotools.referencing.CRS.lookupIdentifier(CRS.java:883)
> at org.geotools.referencing.CRS.lookupEpsgCode(CRS.java:917)
>
> I guess it is the same kind of problem discribed in an other forum post two
> years ago:
> http://www.mail-archive.com/[email protected]/msg09502.html
>
> Do you have any suggesstions to solve the problem?
I've tested with a simple concurrent app making lookups and I can
confirm the issue. I've tracked it down to the authority lookup
and it can be easily reproduced with the following little app:
import org.geotools.factory.Hints;
import org.geotools.referencing.ReferencingFactoryFinder;
import org.opengis.referencing.crs.CRSAuthorityFactory;
public class EpsgScanSample {
private static final Hints FORCE_LONGITUDE_FIRST_AXIS_ORDER = new Hints(
Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
public static void main(String[] args) throws Exception {
for (int i = 0; i < 1000; i++) {
Thread t = new Thread(new Runnable() {
public void run() {
try {
for (final CRSAuthorityFactory
factory : ReferencingFactoryFinder
.getCRSAuthorityFactories(FORCE_LONGITUDE_FIRST_AXIS_ORDER)) {
// do stuff
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
}
}
}
It would seem the org.geotools.factory.FactoryRegistry keeps
state to avoid recursive call, but all threads end up using
the same FactoryRegistry object resulting in issues.
I guess the two options available are to either make
FactoryRegistry fields thread locals or make sure each scan
is using a separate FactoryRegistry object (if at all possible).
Right now I have no time to investigate this further. Can you
open a jira issue and eventually try to take this from here
and see if you can cook up a patch?
Cheers
Andrea
--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel