InterMine ObjectStore operation cancellation

The main InterMine ObjectStore has a mechanism for cancelling queries which are in progress. This was designed so that users clicking on the "stop" or "back" buttons on their browsers while running a very complex query would not keep using SQL server resources that they will not use. To use this feature:

  • Register your thread with a marker object by using the registerRequestId(Object id) method in the thread that will be performing the operation.
  • Start a try block, and perform your operations - as many as you wish.
  • In another thread, call cancelRequest(Object id) with the marker object you registered earlier. This will cancel any operation that is currently running, and prevent any future operations on that thread from starting.
  • In your main thread, catch an ObjectStoreException. In your finally block, deregister the thread by calling deregisterRequestId(Object id) with the same marker object.

For example:

Object requestId = new Object();
os.registerRequestId(requestId);
try {
    os.execute(query);
    ...
} catch (ObjectStoreException e) {
    // Do something
} finally {
    os.deregisterRequestId(requestId);
}

And in another thread:

    os.cancelRequest(requestId);