Aspose Java Concurrency Issues

I don’t believe this issue is limited to just Aspose Words java but it is the first discovery. We have been an aspose user/customer for a number of years during those years this has always been an issue. In the multi-threaded environment our application operates in aspose will lock or freeze. In the past this has required server restarts and also forcing us to a only use a single thread per server dedicated to working with aspose. This creates a bottle neck. In the latest issue I was able to identify the blocking issue. We had 4 separate processes each in their own thread working on creating different word documents. All of those threads became blocked in the StyleCollection class. This is because the StyleCollection class has numerous static variables which are lazy initialized via separate synchronized blocks. This has to be part of what has been causing intermittent issues through out the years. I am looking for more information on other objects within aspose which have synchronization. Is this available and where? Also in the case of the StyleCollection example a potential solution is to simply be able to warm up that class or pre-initialize the static variables. As all the code is obfuscated it is impossible to figured out what part of our creation would be forcing the usage of those variables. I have also not found any way that would be obvious and easy to do any sort of warming process. Any guidance or help would be much appreciated.

@devregistration_jaggaer

It sounds like you’re experiencing significant concurrency issues with Aspose.Words in a multi-threaded environment, particularly related to the StyleCollection class. This can lead to blocking and freezing, especially when multiple threads attempt to access shared resources that are synchronized.

Cause:

The concurrency issues arise from multiple threads trying to access the StyleCollection simultaneously, which can lead to contention and performance degradation.

Solution:

  1. Identify Synchronization Points: Review the Aspose.Words documentation or source code (if available) to identify other classes that may have similar synchronization mechanisms. This will help you pinpoint potential bottlenecks.

  2. Warm-Up Strategy: To mitigate the blocking issue with StyleCollection, implement a warm-up routine. Pre-load or initialize the styles in a single-threaded context before your multi-threaded operations begin. For example:

    Document doc = new Document("your-document.docx");
    // Access styles to trigger initialization
    StyleCollection styles = doc.getStyles();
    for (Style style : styles) {
        // Access each style to ensure they are initialized
        String styleName = style.getName();
    }
    
  3. Single Thread for Document Processing: If feasible, process documents in a single-threaded manner or use a thread pool with a limited number of threads to reduce contention.

  4. Monitor and Log: Implement logging around your document processing to capture when and where threads are getting blocked. This will provide insights into specific operations causing issues.

  5. Contact Support: If the problem persists, reach out to Aspose support with detailed logs and examples of your implementation. They may provide insights or updates regarding thread safety in the library.

Next Steps:

Implement the suggested solutions and monitor the performance. If you continue to face issues, gather logs and prepare to contact Aspose support for further assistance.

Please let me know if this helps or if you have any further questions!

Thanks for the AI response which i have already received from OpenAI. All of which has been suggested has already been tried. The code example also does not initialize these variables. I need documentation or new api methods perform the warming. At this point a brittle java reflection solution has been the most effective. This solution warms or initializes the variable in a single thread prior to any aspose usage.

Help!!!

@devregistration_jaggaer Could you please create a simple application that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.

The image attached show the following threads which are in red and blocked by the style collection. All of which are working on different document instances.

@devregistration_jaggaer Thank you for additional information. But to analyze the problem it is required to reproduce the problem on our side. So please create a simple application that will allow us to reproduce the problem. We will test the scenario on our side and provide you more information.