From: FrenKy on 16 May 2010 09:36 Hi *, can someone please suggest thread safe DOM implementation with support for Xpath for reading XML files? Or if someone has a good source for hints how to make some dom implementation thread safe... Thanks in advance!
From: Lew on 17 May 2010 09:48 On May 16, 9:36 am, FrenKy <frenky_...(a)gmail.com> wrote: > Hi *, > can someone please suggest thread safe DOM implementation with support > for Xpath for reading XML files? > > Or if someone has a good source for hints how to make some dom > implementation thread safe... > 'synchronized' keyword. What part do you want to be thread safe, parsing the XML document or accessing the DOM that results? The former is almost certainly not practicable. The second boils down to what you do to make any object model thread safe. -- Lew
From: FrenKy on 18 May 2010 15:58 On 17.5.2010 15:48, Lew wrote: > What part do you want to be thread safe, parsing the XML document or > accessing the DOM that results? > > The former is almost certainly not practicable. The second boils down > to what you do to make any object model thread safe. > > -- I'm building the DOM in a single thread and then I'm reading it in several threads (usually not more then 20, depending on number of CPUs, e.g. I'm running it sometimes on 100+ CPU machines). But sometimes (seldom) I get NullPointer exception on most unexpected locations during read operations... But _always_ when I've already built XML. Threads are started after xml file is built. So I figured I'm doing something wrong with multithreading and sync. Same application ran in single threading mode does not throw NullPointerException. But I guess from your answer I should take another look at how I'm doing access to xml dom... That is why I've asked if there is some thread safe implementation for reading (guess I missed this part in my first post) xml DOM elements.
From: Lew on 18 May 2010 16:12 On 05/18/2010 03:58 PM, FrenKy wrote: > I'm building the DOM in a single thread and then I'm reading it in > several threads (usually not more then 20, depending on number of CPUs, > e.g. I'm running it sometimes on 100+ CPU machines). Please provide an SSCCE. <http://sscce.org/> Without seeing what you're actually doing it is hard to know what you're doing wrong. > But sometimes (seldom) I get NullPointer exception on most unexpected > locations during read operations... But _always_ when I've already built > XML. Threads are started after xml file is built. So I figured I'm doing > something wrong with multithreading and sync. Same application ran in > single threading mode does not throw NullPointerException. Your description does not indicate what is wrong, but if the reading threads are started from the same thread that build the DOM and only after the DOM is completely constructed, and if nothing is changing the DOM, then threading is not the problem. > But I guess from your answer I should take another look at how I'm doing > access to xml dom... > That is why I've asked if there is some thread safe implementation for > reading (guess I missed this part in my first post) xml DOM elements. Once again, "[it] boils down to what you do to make any object model thread safe." You didn't even describe your problem, much less show it, in your first post. Now you've described your problem without showing it. With only a vague, indirect description of your problem, one can only provide a vague, indirect solution to it. If it were a threading issue, then one would have to conclude that something is altering your object model without proper synchronization after the threads have started, or that they are started from a thread that does not have proper synchronization with the thread that built the model. Otherwise it's not a threading issue. -- Lew
From: Daniel Pitts on 18 May 2010 16:34
On 5/16/2010 6:36 AM, FrenKy wrote: > Hi *, > can someone please suggest thread safe DOM implementation with support > for Xpath for reading XML files? > > Or if someone has a good source for hints how to make some dom > implementation thread safe... > > Thanks in advance! XPath itself isn't multithread safe. Are you sure you need multithreading for your use-case? If you have something that is that performance intensive, perhaps a different approach is called for (StAX/SAX based parsing of the XML file, Building a domain object graph instead of a DOM, etc...) -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/> |