Hi,
I am trying to convert docx file using groupdocs 16.10.1 for Java. If I run in single thread, it works fine. But when I run using multithreading, it’s failed.
It seems that ConversionHandler is not thread safe.
Hi There,
Thanks for posting your concerns.
Can you please share problematic file and sample code with us. We’d like to investigate that at our end.
Best wishes
Hi Atir,
Thank you for the reply. Please find the attachment for the snipped code.
Hi Agustino,
Can you please share the problematic file as well? We’ll appreciate your cooperation.
Kind regards
Hi Atir,
Please find the file in the attachment.
Hi Agustino,
Thanks for your cooperation. We’ll update you soon about the investigation’s outcome.
Best wishes
Hi Agustino,
Can you please change,
private static final ConversionHandler CONVERSION_HANDLER = new ConversionHandler(Utilities.getConfiguration());
to this:
private final ConversionHandler CONVERSION_HANDLER = new ConversionHandler(Utilities.getConfiguration());
or any other way to make the ConversionHandler instance member, don’t make it static and see if you still face same issue.
Kind regards
Hi Atir,
I have tried your suggestion. It works fine. For every conversion, if I need to instantiate ConversionHandler, will it be expensive call?
Thanks
Hi Agustino,
I have tried your suggestion. It works fine.
Good to know that.
As far as your second question is concerned, it won’t be very much expensive if you instantiate ConversionHandler and then destroy the object for that specific Conversion call and instantiate again for next call and so on.
After each conversion call you can do:
conversionHandler = null;
It will be automatically deleted by the garbage collector (not immediately, but eventually).
We’d suggest you to observe/compare conversion performance in both cases (Instantiating ConversionHanlder each time without destroying object and with destroying object after each conversion call).
Kind regards
Hi Agustino,
Additionally, please note that the instantiation of ConversionHandler is light weight and very quick operation. It won’t be expensive, no matter if you destroy object or not. Hence, we’d suggest you to instantiate ConversionHandler each time for each conversion call (that is already your basic need).
Many thanks
Hi Atir,
Thank you for the response. I will change to local variable.
Hi Atir,
I am getting another error after moving conversion handler to local variable:
Error occurred while getting contents of document: At most 4 elements (for any collection) can be viewed in evaluation mode.
class com.groupdocs.conversion.internal.c.a.pd.internal.ms.System.z87: At most 4 elements (for any collection) can be viewed in evaluation mode
Is it expected result while I am using trial license?
Thanks
Hi Agustino,
At most 4 elements (for any collection) can be viewed in evaluation mode
This error occurs when you are evaluating the API in trial mode.
Is it expected result while I am using trial license?
As you are using trial license to evaluate the API, there can be following possibilities:
- License is not applied properly
- Trial license is expired
If trial license is not expired, please share the code with us where you are applying license.
Kind regards
Hi Atir,
Thanks for highlighting this. I have so many classes for testing and this class I miss out to apply the license. Sorry about that
Hi Atir,
I am still getting the same error. This error happened intermittent.
Please find the stacktrace and the source file in the attachment.
Thanks
Hi Agustino,
Thanks for sharing the concerned files.
We’ve logged your issue in our internal issue tracking system with ID - CONVERSIONJAVA-385. As we have any update, we’ll notify you.
Have a nice weekend!
Kind regards
@agustinoalim,
We have an update regarding CONVERSIONJAVA-385. The workaround is to instantiate conversion handler in each thread.
If you change:
private static final ConversionHandler CONVERSION_HANDLER = new ConversionHandler(Utilities.getConfiguration());
to
private final ConversionHandler CONVERSION_HANDLER;
and instantiate the conversion handler in MyThread constructor:
this.CONVERSION_HANDLER = new ConversionHandler(Utilities.getConfiguration());
It will resolve your issue.