Interruption is not supported when save a word or cell


it costs a long time when converts XLS to XLSX, I want to interrupt the convert process after a period. But the convert process cannot be terminated.

ExecutorService es = Executors.newSingleThreadExecutor();
Future future = null;
try {
Callable callable = new Callable() {
public Integer call() {
int i = 0;
try {
Workbook workbook = new Workbook(srcFilePath);, FileFormatType.XLSX);
} catch (Exception e) {
System.out.println(“interrupt, then quit 1”);
return new Integer(-1);
return new Integer(i);
future = es.submit(callable);
iRet = future.get(500, TimeUnit.MILLISECONDS);
catch (Exception e) {
System.out.println(“interrupt, then quit 2”);
iRet = new Integer(-1);
finally {



Thanks for your query.

Aspose.Cells does support to interrupt loading/saving process while working with large MS Excel files, see the document for your reference:

Hope, this helps a bit.


And how to interrupt loading/saving process Word files ?



You can use InterruptionToken class instance and bind it to the current thread executing Aspose.Words code. Then calling Interrupt on the token instance should break the execution. Sample inherited class code is as follows:

using System.Threading;
using Aspose.Words;
namespace MyCompany
    /// <summary>
    /// My Aspose document.
    /// </summary>
    public class MyDocument : Aspose.Words.Document
        public MyDocument(string fileName) : base(fileName) {}
        public bool TryToSave(string fileName, int timeout)
            InterruptionToken token = new InterruptionToken();
            bool finished = SaveWithTimeout(token,
                () =>
                }, timeout);
            return finished;
        private bool SaveWithTimeout(InterruptionToken token, ThreadStart threadStart, int timeout)
            Thread workerThread = new Thread(threadStart);
            bool finished = workerThread.Join(timeout);
            if (!finished)
            return finished;

Sample usage is as follows:

MyDocument myDoc = new MyDocument(@"C:\BigDoc.docx");
bool done = myDoc.TryToSave(@"C:\BigDoc.pdf", 60000);
Console.WriteLine(done ? "Converted" : "Interrupted by timeout.");


I cannot find InterruptionToken class in JAVA API . so how to do it in JAVA?


Fail to interrupt saving process, and the dstFile has been saved success!

    long startTime = 0;
    long endTime = 0;  
try {
            final InterruptMonitor interruptMonitor = new InterruptMonitor();
            final Workbook workbook = new Workbook(srcFilePath);
            new Thread(new Runnable() {
                public void run() {
                    try {
                    } catch (InterruptedException e) {
                    // Interrupt the process
                    System.out.println("Interrupting the save thread at "
                            + System.currentTimeMillis());
            startTime = System.currentTimeMillis();
  , FileFormatType.XLSX);
        } catch (com.aspose.cells.CellsException e ){
            if (e.getCode() == ExceptionType.INTERRUPTED) {
                System.out.println("The save thread finishes at "
                        + System.currentTimeMillis());
        catch (Exception e) {

    endTime = System.currentTimeMillis();
    System.out.println("startTime:" + startTime + ",endTime:" + endTime);

Out is ,
Interrupting the save thread at 1531214514754



I am afraid, in Aspose.Words for Java we do not have InterruptionToken class because Aspose.Words for Java relies on Java’s Thread functionality. The Java code will look something like this:

public void testThreadInterruption() throws InterruptedException
    // run Aspose.Words long operation in a separate thread
    Thread infiniteThread = new Thread(infiniteProcessingLoop());

    // interrupt it in a while

    // wait till it dies

    // check if it is dead
    if (infiniteThread.getState() == Thread.State.RUNNABLE)"Thread didn't stop properly");

private static Runnable infiniteProcessingLoop()
    return new Runnable()
        public void run()
                while (true)
                    new Document("pathToTestDoc").updatePageLayout();
            catch (Exception ex)




I noticed it saves the Excel file too. We will check it out soon.
For the time being could you add a line to your code segment, it should work fine:
Sample code:

startTime = System.currentTimeMillis();, FileFormatType.PDF);//add a variable to specify the .pdf file., FileFormatType.XLSX);

A corrupted PDF file might be created with less file size. The XLSX file will not be created.

Let us know if it works fine.


It works fine when add a line to save to PDF, but is there other better solutions ?


So there’s no Interruption in Aspose.Words for Java ? This Java code cannot stop the save process.



Please spare us some time as we need to evaluate it thoroughly and may come with better alternative (if possible).



We have evaluated the issue regarding saving XLSX file in interruption process. We need to improve the relevant internal modules by adding more check points (higher frequency) while saving the Excel files. I have logged a ticket with an id “CELLSJAVA-42677” for your issue. We will look into it soon.

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



This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-42677”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Keep in touch.



Please try our latest version/fix (attached): Aspose.Cells for Java v18.7.5:

Your issue “CELLSJAVA-42677” should be fixed in it.

Let us know your feedback.
Aspose.Cells for Java (6.3 MB)


The issues you have found earlier (filed as CELLSJAVA-42677) have been fixed in Aspose.Cells for Java 18.8. You can also get the latest Aspose.Cells for Java version from Maven repos. with simple configurations. Please see the document for your reference:

This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi