Results 1 to 2 of 2
  1. #1
    gdev is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    Default Problem with use of Multi threading with DOM object

    My multi threaded application processes and loads records into an ECM repository. For reconcliation purposes , I am trying to build an XML format report with the results of the processing per record, while processing is underway per thread. The method below is called from every thread wvery time its ready to append an element to the DOM with the status.
    Java Code:
    	public void writeReportLine(Element rptLine) {
    		// Write output to report file
    		synchronized (XMLReportHandler.class) {
    			reportOutput.getDocumentElement().appendChild(rptLine);
    		}
    	}
    After all priocessing completes, the below method is called only once by every thread to write to the File on the file system:

    Java Code:
    	public void writeToReportFile() {
    		synchronized (XMLReportHandler.class) {
    				try{
    				  //write the content into xml file
    				  TransformerFactory transformerFactory = TransformerFactory.newInstance();
    				  Transformer transformer = transformerFactory.newTransformer();
    				  DOMSource source = new DOMSource(reportOutput);
    			
    				  StreamResult result =  new StreamResult(f);
    				  transformer.transform(source, result);
    
    				}catch(TransformerConfigurationException e){
    					logger.error("** Error getting xml report document object: " + e);
    					e.printStackTrace();
    				}catch(TransformerException e){
    					logger.error("** Error getting xml report document object: " + e);
    					e.printStackTrace();
    				}
    			}
    	}
    The problem is that when under load, the threads just seem to hang while the transformer.transform(source, result) call keeps getting executed until there is an interrupt of some sort. I was able to examine a section of what was appended and it was status for records that had finished processing very early in the process based on my application logs. Once an interrupt is recieved , it looks like the threads recover.

    Any idea whats wrong in here ? Thanks in advance for your advice - I have been stuck trying to figure out where the problem out for days! Now that I know where the problem is , I cant figure out a solution. Looking for multi threading gurus..

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Problem with use of Multi threading with DOM object

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: 11-27-2012, 11:07 AM
  2. Multi-Threading
    By TonyDaniels in forum New To Java
    Replies: 4
    Last Post: 03-09-2012, 06:16 PM
  3. Multi-Threading
    By TonyDaniels in forum Advanced Java
    Replies: 1
    Last Post: 03-09-2012, 05:52 PM
  4. multi-threading problem
    By imorio in forum New To Java
    Replies: 1
    Last Post: 04-25-2011, 06:52 PM
  5. Problem in Multi threading.
    By Chetans in forum Advanced Java
    Replies: 3
    Last Post: 03-23-2010, 04:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •