xml ファイルを html ファイルに変換する次のコードがあります。これは多くのスレッドによってアクセスされます。変換メソッドは毎回コンテンツを追加するだけです。これは、最初のスレッドのコンテンツが後続のすべてのスレッドの html ファイルに保持されることです。
public class CreateHTML
{
TransformerFactory tFactory;
Source xslDoc;
Source xmlDoc;
OutputStream htmlFile;
public CreateHTML(String xslDocFileName,String xmlDocFileName,String outputFileName) throws FileNotFoundException
{
xslDoc=new StreamSource(xslDocFileName);
xmlDoc=new StreamSource(xmlDocFileName);
htmlFile=new FileOutputStream(outputFileName);
}
public synchronized void createOutputFile() throws Exception
{
try
{
tFactory=TransformerFactory.newInstance();
tFactory.setAttribute("indent-number",new Integer(2));
Transformer transformer = tFactory.newTransformer(xslDoc);
transformer.setOutputProperty(OutputKeys.INDENT,"yes");
transformer.transform(xmlDoc, new StreamResult(htmlFile));
}
catch (TransformerException ex)
{
Logger.getLogger(CreateHTML.class.getName()).log(Level.SEVERE, null, ex);
throw ex;
}
}
}