Cancelling a running report task
To cancel a running task call the IEngineTask.cancel( ) method. All the tasks that run and render reports implement and extend the IEngineTask interface. If the application cancels a task that is running a report, the task stops generating the report content. If the task has started a query on a database, the database continues to run the query to completion.
How to cancel a running report task
1 Define a thread class as an inner class to cancel the report. In Listing 9‑15, the name of this class is CancelReport.
2 Within the code that creates the task, create an instance of the CancelReport class, as shown in the following line:
CancelReport cancelThread = new CancelReport( "cancelReport", task);
3 Test for a condition. Then, use the CancelReport object to cancel the report, as shown in the following line:
cancelThread.cancel( );
Listing 9‑15 Defining a class to cancel an engine task
private class CancelReport extends Thread
{
private IEngineTask eTask;
 
public CancelReport( String myName, IEngineTask task )
{
super( myName );
eTask = task;
}
 
public void cancel( )
{
try {
Thread.currentThread( ).sleep( 100 );
eTask.cancel( );
System.out.println( "#### Report cancelled #####" );
}
catch( Exception e )
{
e.printStackTrace();
}
}
}