3

Because if it thread safe I can use just one instance of VTDGen for the entire application.

Right now I am instantiating a new VTDGen for every requests, I am thinking of making it static so that it is initialized just once.

Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154

1 Answers1

1

What do you mean exactly by thread safe? After VTDGen processes one document, and you get vtdNav from it, VTDGen can certainly be reused to process the next document. So in tht sense, it is thread safe, not just in Java, but in C and C++ as well..

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
  • I am processing lots of small xml documents. So I thought if I make VTDGen a class variable (`static`) I could further save some time. But since I cannot guarantee there will be only 1 document processed at a given time then I guess I have no choice but to instantiate VTGen for every requests in my servlet. – Rosdi Kasim Apr 23 '11 at 01:25
  • I don't see any issue with that since vtdGen is not that big a data struture, so instantiation cost is small – vtd-xml-author Apr 23 '11 at 02:39
  • @vtd-xml-author As we are currently evaluating VTD in some tests we currently compare it to SAX and we noticed that the initial setup of parsing takes quite long for VTD compared to SAX (16 ms on average for SAX, 226 ms (min 77 ms, max 441 ms) on average for VTD). On consecutive parses VTD is on average 1/3 faster then SAX (for certain documents, however, it is almost always slower then SAX). Can you elaborate a bit on the high initial setup cost and what VTD does on consecutive parses which results in a much lower parsing time? Note, we did no real warm-up phase – Roman Vottner Sep 15 '16 at 14:39
  • @RomanVottner--can't exactly comment without looking at your code... did you include io cost? are you using server jvm? Do you need xpath? how much of a factor is the initial set up time? did you look at vtd-xml's own benchmark code... use that as a referece if you can – vtd-xml-author Sep 15 '16 at 20:31
  • @vtd-xml-author how can I evaluate xpaths in multiple threads, I have 100's of xpaths that need to evaluated, so I want to use multi threaded approach, but running into issues. – BJC Feb 02 '18 at 18:41
  • @what issue are you running into? – vtd-xml-author Feb 02 '18 at 20:24
  • @vtd-xml-author here is the question I posted in SO https://stackoverflow.com/questions/48593552/using-vtd-in-multithreaded-app – BJC Feb 03 '18 at 03:35
  • @vtd-xml-author, I posted a solution , would be grateful if you provide your comments on the same https://stackoverflow.com/questions/48593552/using-vtd-in-multithreaded-app – BJC Feb 03 '18 at 05:01