is it a good thing to use XML::Writer in a multithread fashion?

The way you are doing it, no.

Since both threads are writing to the same file, and they cannot safely both be writing at the same time, you would have to serialise them to prevent them intermingling their outputs. And that means there would be nothing gained by threading that paret of the process.

But, reading the subtext of your question, the gain you are hoping for is not in the writing of the XML output, but in the sourcing of the data written. That is to say, you imply that you are fetching data from two (or more) sources. As you do not show where or how you are sourcing that data, it is impossible to say whether there would be any advantage in using threading for that part of the process.

If, for example, you are fetching the data from two different servers, there may be some gains to be had by overlapping the fetching of the data, and then feeding the data fetched back to a single thread for writing to a file as XML.

But you'll need to describe the whole process from end to end to get good wisdom on that.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^3: Multithreaded xml writing using XML::Writer by BrowserUk
in thread Multithreaded xml writing using XML::Writer by DreamT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.