We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Infinite loop issue when save to HTML

for (int z = 0; z < 2; z++) {
final int zz = z;
new Thread(){
@Override
public void run() {
Workbook wb = new Workbook();
Worksheet worksheet = wb.getWorksheets().get(0);
Cells cells = worksheet.getCells();
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
Cell cell = cells.get(x, y);
cell.setValue(Math.PI * x / y * zz);
BorderCollection borders = cell.getStyle().getBorders();
Border top = borders.getByBorderType(BorderType.TOP_BORDER);
top.setArgbColor((x << 16) | y | 0xFF000000);
top.setLineStyle(CellBorderType.DASH_DOT);
}
}
try {
wb.save("C:/Users/admin/Desktop/t/t/" + zz + ".html");
} catch (Exception e) {
}
}
}.start();
}



I use cells-8.6.3.4

Debug above codes with IDE( Eclipse etc.)
And toggle a break point at com.aspose.cells.zafp.a(String, boolean)

Two threads will break on this method,
and in this method, it call HashMap.get and HashMap.put which is not thread-safe.

In some case this make JVM in infinite loop.
It should use java.util.concurrent.ConcurrentHashMap or java.util.Collections.synchronizedList to prevent.

Hi Xiong,


Thank you for contacting Aspose support.

I have tested your code in a simple console application while targeting Aspose.Cells for Java 8.6.3.6 & JDK 1.8.0_66 under Windows 10 x64. Unfortunately, I am not able to observe any unexpected aborts or the process being held in an infinite loop. Could you please give a try to the aforementioned revision of Aspose.Cells for Java on your end as well? In case the problem persists, please provide more details of your test environment such as follow.

  • Operating system version & architecture
  • JDK vendor, version & architecture
  • Locale of your machine
  • JVM arguments set for the process/program, if any
  • Any other details that you think will help us isolate the problem cause

I am not able to occur each time, because HashMap is not always error.


Debug codes with IDE, two threads step into this method concurrent, mean multiple threads access a hash map concurrently!

In HashMap’s java documents, you can note a statement “Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externallyd”.

But aspose doesn’t synchronized the HashMap!

So in some case, infinite loop happen.

Hi Xiong,


Thank you for providing additional details, however, we also require your environment details (as requested in previous response) to replicate the issue. Please note, so far I am not able to find any issue while executing your code on Windows 7 & Windows 10 x64 against JDK 1.8 & Aspose.Cells for Java 8.7.0 (latest at the moment).
I can't find a way to replicate the issue each time. In fact this issue occur rarely, but once occur the code never return.

I can do below modification for replicate Aspose call HashMap.put concurrently with one instance.


I use JDK1.6.0_30 and cells-cells-8.7.0, I change HashMap.java, add some code in put(This modification only let Eclipse can add breakpoint at special line):
//HashMap.java
public V put(K key, V value) {
//Code add here
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (stackTrace.length > 2 && stackTrace[2].getClassName().contains("zafp"))
System.out.println();
//Code add end
//Original source code
if (key == null)
return putForNullKey(value);
...
//End HashMap.java

//Test Code
for (int z = 0; z < 2; z++) {
final int zz = z;
new Thread() {
public void run() {
Workbook wb = new Workbook();
Worksheet worksheet = wb.getWorksheets().get(0);
Cells cells = worksheet.getCells();
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
Cell cell = cells.get(x, y);
cell.setValue("" + Math.random() * Math.PI * x / y * zz);
BorderCollection borders = cell.getStyle()
.getBorders();
Border top = borders
.getByBorderType(BorderType.TOP_BORDER);
top.setArgbColor((x << 16) | y | 0xFF000000);
top.setLineStyle(CellBorderType.DASH_DOT);
}
}
try {
wb.save("C:/" + zz + ".html");
} catch (Exception e) {
}
}
}.start();
}
//End Test Code;

Compile HashMap.java with -g option and replace original class file in rt.jar,
Add a breakpoint in HashMap.java ,in line System.out.println,
debug test code in Eclipse



Two thread break on these code System.out.println()

Please note variable "this" is same id of two threads, mean an instance of HashMap change Entry link concurrently!


This is not thread-safe modification!


And if you use this test code, sometimes will make JVM in infinite loop, event all threads done , size of map is wrong , not equals N.
If you change HashMap to ConcurrentHashMap, it work fine.

static Map map = new HashMap();
static int N = 10000;
static CountDownLatch startSignal = new CountDownLatch(1);
static CountDownLatch doneSignal = new CountDownLatch(N);
public static void main(String[] args) {
for (int i = 0; i < N; i++) {
final int j = i;
new Thread(new Runnable(){
public void run() {
try {
startSignal.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
map.put(Thread.currentThread().getId()+""+j, "test");
doneSignal.countDown();
}
}).start();
}
startSignal.countDown();
try {
doneSignal.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("done,size:" + map.size());
}

Hi,


Thank you for providing additional information. Please spare me little time to reevaluate the scenario while considering the recently shared information, and discuss it with the product team, if required. I will shortly get back to you with updates in this regard.

Hi again,


This is to update you that upon discussion with the concerned member of the product team, I have logged an investigative ticket with Id CELLSJAVA-41711 in our bug tracking system. We will require some more time to schedule the analysis for this scenario, and to sort out the problem cause. In the meanwhile, we will keep you posted with updates in this regard.

Hi,

Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for Java v8.7.0.2 and let us know your feedback.

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


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