Checking the status of a running report task
The BIRT Report Engine supports checking the status of any engine task and cancelling that task. Typically, an application uses a separate thread to perform these actions. To check the status of a running report, use the EngineTask.getStatus( ) method, which returns one of the following values:
*IEngineTask.STATUS_NOT_STARTED. The task has not started.
*IEngineTask.STATUS_RUNNING. The task is currently running.
*IEngineTask.STATUS_SUCCEEDED. The task completed with no errors.
*IEngineTask.STATUS_FAILED. The task failed to execute.
*IEngineTask.STATUS_CANCELLED. The task was cancelled.
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 5‑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 5‑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();
}
}
}