Saving multiple workbooks in concurrent threads using Aspose.Cells for Java

My Code:

Workbook src = getWorkbook();
ByteArrayOutputStream out = new ByteArrayOutputStream();
src.save(out, SaveFormat.XLSX);


When too many concurrent thread call save (like 200 threads)


In Aspose.Cells 8.8.2
In class com.aspose.cells.a.c.zp method
public static String a(DateTime datetime, String s)
{
if(datetime == null)
return "";
else
return a(za.a(), s).format(datetime.j());
}


It use SimpleDateFormat.format DateTime to String,
But this method is not thread safe!! And Aspose.Cells doesn't use synchronized it!

It will throw exception like pic in attachments

It seems in aspose-cells-17.1.0.jar has the same issue.

In my case, I will put the cache hashtable in a ThreadLocal variable


Then can make it thread safe, and cacheable to improve performance.

Hi,


Thanks for sharing details about your issue.

Could you write a sample console JAVA program (.java file) to reproduce the issue on our end. Also attach your resource files (e.g template Excel file if you have any). We will check it soon.

Thank you.
I reproduce this issue very difficult, and can't give you a reproduce sample code.

But in Eclipse, add breakpoint at
com.aspose.cells.a.c.zp.a(com.aspose.cells.DateTime, java.lang.String, com.aspose.cells.b.a.c.za)


and run this code

int N = 2;
for (int i = 0; i < N; i++) {
new Thread() {
public void run() {
try {
Workbook wb = new Workbook("C:/x.xlsx");
wb.save(new ByteArrayOutputStream(), SaveFormat.XLSX);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}


Eclipse will break on method com.aspose.cells.a.c.zp.a in Thread-1 and Thread-2

Use "step into" until stack frame like:

Thread [Thread-1] (Suspended)
java.text.SimpleDateFormat(java.text.DateFormat).format(java.util.Date) line: 345
com.aspose.cells.a.c.zp.a(com.aspose.cells.DateTime, java.lang.String, com.aspose.cells.b.a.c.za) line: not available
com.aspose.cells.DateTime.a(java.lang.String, com.aspose.cells.b.a.c.za) line: not available
com.aspose.cells.zzb.a(com.aspose.cells.DateTime) line: not available
com.aspose.cells.zuc.a(com.aspose.cells.zciw) line: not available
com.aspose.cells.zvc.f() line: not available
com.aspose.cells.zvc.c() line: not available
com.aspose.cells.zvb.a(com.aspose.cells.Workbook, com.aspose.cells.b.a.d.zm, int, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.a(com.aspose.cells.b.a.d.zm, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.save(java.io.OutputStream, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.save(java.io.OutputStream, int) line: not available



Thread [Thread-2] (Suspended)
java.text.SimpleDateFormat(java.text.DateFormat).format(java.util.Date) line: 345
com.aspose.cells.a.c.zp.a(com.aspose.cells.DateTime, java.lang.String, com.aspose.cells.b.a.c.za) line: not available
com.aspose.cells.DateTime.a(java.lang.String, com.aspose.cells.b.a.c.za) line: not available
com.aspose.cells.zzb.a(com.aspose.cells.DateTime) line: not available
com.aspose.cells.zuc.a(com.aspose.cells.zciw) line: not available
com.aspose.cells.zvc.f() line: not available
com.aspose.cells.zvc.c() line: not available
com.aspose.cells.zvb.a(com.aspose.cells.Workbook, com.aspose.cells.b.a.d.zm, int, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.a(com.aspose.cells.b.a.d.zm, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.save(java.io.OutputStream, com.aspose.cells.SaveOptions) line: not available
com.aspose.cells.Workbook.save(java.io.OutputStream, int) line: not available

You will find "this" in Thread-1 and Thread-2 are both SimpleDateFormat, and have same id that mean they are the same instance. Because SimpleDateFormat is not thread safe, in some rare case will throw "ArrayIndexOutOfBoundsException".

Hi,


Thanks for providing us further details and template file.

I have logged an investigation ticket with an id “CELLSJAVA-42184” for your issue. We will evaluate your issue thoroughly on our end and try to figure it out soon.

Once we have an update on it, we will let you know here.

Thank you.

Hi,


We did evaluate your issue “CELLSJAVA-42184”. We have fixed it now. We will soon share the Download link for the new version/fix here, so you could try the new version and let us know your feedback.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-42184) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.