#1 Make DomParser.parse() thread safe


With vCard4J version 1.1.3, the DomParser class is not
thread safe. This wouldn't be so much of an issue,
except that the process of instantiating a DomParser is
pretty heavy: you have to read in and parse the DTD for
the various vCard specs each time. This means that in
high-performance situations (such as, for example, on a
web application server) where multiple simultaneous
requests might be coming in, you'll have to create and
destroy DomParsers all the time.

A couple of solutions spring to mind:

1) make the parse method thread safe. This might be
tricky, especially if the DomParser contains a SAX
parser and is using that during the parse process.

2) Create a DomParserFactory that reads the config
files when it gets instantiated, and then provides a
getDomParser() method that builds a new DomParser from
the already read-in files. This is still kind of heavy,
but at least we don't have to hit the filesystem every
time we want a DomParser.


  • Yann Duponchel

    Yann Duponchel - 2003-12-09
    • assigned_to: nobody --> duponchel
    • status: open --> closed
  • Yann Duponchel

    Yann Duponchel - 2003-12-09

    Logged In: YES

    Reasonnable case, I will add it soon. - Yann.

  • Yann Duponchel

    Yann Duponchel - 2003-12-26

    Logged In: YES

    - made parse() thread safe (DONE)

    - DTDs are never read they are just provided for information

    - There is no reason to throw away DomParser, parse() can be
    invoked repeatedly: no reason to reinstantiate it (UNCHANGED)

    - configuration file can also be passed at creation time and
    cached if someone wants to create multiple instances of
    DomParser (UNCHANGED)

    - creating a DomParser is not time consuming if the config
    file is given as a parameter. What takes time is the parsing
    itself (UNCHANGED)

    - Need to create Factories... (TODO)

    - for some reason this feature request was closed, that has
    never been the intent...

  • Yann Duponchel

    Yann Duponchel - 2003-12-26
    • status: closed --> closed

Log in to post a comment.