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

Free Support Forum - aspose.com

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