Interrupt the save operations (Java)

Hi, I’d like to know when the InterruptToken will land in java world (Sorry it is already the case).
We have cases where we save a Words document as image and it take too long.
We’d rather kill the processing thread. But sadly it does not seems to work.

Another question is it possible to save only a page of a document. We’d like to provide a per page preview of the document.

@PierreS

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. You can use following code example to achieve your requirement. Hope this helps you.

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

    // interrupt it in a while
    Thread.sleep(2000);
    infiniteThread.interrupt();

    // wait till it dies
    infiniteThread.join(5000);

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

private static Runnable infiniteProcessingLoop()
{
    return new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                while (true)
                {
                    Document doc = new Document("input.docx");
                    doc.save("output.png");
                }
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }

        }
    };
}

Thanks for your answer

Hello.
Is this information still relevant, is there no other way of interrupting the generation of a document ?
I am using a FutureTask to generate a document using Aspose.Words for Java and I want to stop the process if it takes longer then 10 minutes. Though the task is canceled, sometimes the generation continues and the thread is released at a later time, when the generation ends.
I am using an older version of Aspose (18.2), it would be nice to know if a newer version can help deal with this problem.
Thank you

@miha.cojocaru The code is relevant.
In additional you can use IDocumentSavingCallback to control document saving process.

You can find a code examples in our .NET documentation, you can easily translate them to Java:
https://reference.aspose.com/words/net/aspose.words.saving/idocumentsavingcallback/

Also, you can consider using IPageLayoutCallback for interrupting layout process, for example if you need to render only the first page of the document.