Free Support Forum - aspose.com

Saving document

Hi,

I have a query related to saving of word document. Do we need to schronize document save call ? If it is not synchronized will it cause any problem ?

Thanks,
Gopal

Hi Gopal,

Thanks for your request. No you do not need to synchronize Save method call. It should not cause any problems.

Best regards,

Hi,

Thanks for your quick response.

We have multi threaded applicatiion, each thread uses a different word document for processing & all the thread might call save document at the same time with different document instance. We had synchronized this save api earlier, the code sinnepet is given below for you reference. After removing the synchronization for the API, i am getting exception, which is attached as document.


Old Code:
public synchronized static ByteArrayOutputStream saveDocument(Document document) throws Throwable {
ByteArrayOutputStream baos = null;
if (null != document) {
baos = new ByteArrayOutputStream();
document.save(baos, SaveFormat.DOC);
baos.close();
}
return baos;
}

New Code:
public static ByteArrayOutputStream saveDocument(Document document) throws Throwable {
ByteArrayOutputStream baos = null;
if (null != document) {
baos = new ByteArrayOutputStream();
document.save(baos, SaveFormat.DOC);
baos.close();
}
return baos;
}

Kindly suggest what is the mistake i am doing.

Thanks,
Gopal

Hi

Thank you for additional information. Does this occur with all documents or only with some particular documents? Could you please attach sample documents that causes this problem.

Which version of Aspose.Words for Java do you use? Have you tried with the latest version? You can download it from here:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

Best regards,

Hi,

please find attachment of a sample file which is causing the above exception. I have few bookmarks in this document & i have data to insert in the bookmark location. I load this file into Aspose Document & insert the data in the bookmark location & call save api, at that time i am getting the above exception.

I am 4.0.3.0 version of aspose word.


Thanks & Regards,
Gopal

Hello

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java. Please try using more recent version of Aspose.Words (10.2.0) and let me know how it goes on your side.

You can download the latest version from here:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

Best regards,

Hi ,

I cannot upgrade Aspose Word now, since i have more impacts & this is an interment issue. If i try once agin it works fine.

Regards,
Gopal

Hello

Thanks for your request. Please note, all fixes and new features are added to new versions of Aspose.Words. So there is no way to get fix of this problem without update to the latest version.

Best regards,