Hi There...
Got some Problems which indicate that Flickrj is not Thread-Safe. Here is an extract of the Exception-Stacktrace:
14:50:33,261 ERROR [FlickrSearchProvider] An IO or SaxParser Exception occured for the flickr response
org.xml.sax.SAXException: FWK005 parse may not be called while parsing.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.aetrion.flickr.REST.get(REST.java:98)
Does anybody know something about that?
Logged In: YES
user_id=1346900
Originator: NO
Not really. If the XML-parser is not thread-save, can't it be replaced?
System.setProperty("javax.xml.parsers.SAXParserFactory","?")
Logged In: YES
user_id=715042
Originator: NO
According to Sun (http://java.sun.com/developer/technicalArticles/xml/JavaTechandXML_part3/)
the parser should be pooled per thread.
So, storing the parser in a thread-local would seem a good solution to the problem.
I'll try this and submit a patch after some testing.
I suffer a lot from this problem, since I have a very slow quad-CPU server which really gives many opportunities for this problem. It occurs often when having more than two concurrent visitors.
Reusing and Pooling Parsers
An XML application may have to process different types of documents (such as documents conforming to different schemas), and these documents can be accessed from different sources. A single parser may be used (per thread of execution) to handle documents of different types successively just by reassigning the handlers according to the source documents to be processed. Since they are complex objects, parsers may be pooled so that they can be reused by other threads of execution, reducing the burden on memory allocation and garbage collection. Additionally if the number of different document types is large and if the handlers are expensive to create, handlers may be pooled as well. The same considerations apply to style sheets and transformers.
Logged In: NO
You can Fix this BUG:
Add a global static MUTEX to the File REST.java
private static Object mutex = new Object();
In the Line 144 to 145 replace:
<code>
Document document = builder.parse(in);
Response response = (Response) responseClass.newInstance();
response.parse(document);
</code>
With:
<code>
Response response = null;
synchronized (mutex) {
Document document = builder.parse(in);
response = (Response) responseClass.newInstance();
response.parse(document);
}
</code>