6.4. Closing the Connection

Documentation

VoltDB Home » Documentation » Using VoltDB

6.4. Closing the Connection

When the client application is done interacting with the VoltDB database, it is a good practice to close the connection. This ensures that any pending transactions are completed in an orderly way. The following example demonstrates how to close the client connection:

try {
    client.drain();
    client.close();
} catch (InterruptedException e) {
    e.printStackTrace();
}

There are two steps to closing the connection:

  1. Call drain() to make sure all asynchronous calls have completed. The drain() method pauses the current thread until all outstanding asynchronous calls (and their callback procedures) complete. This call is not necessary if the application only makes synchronous procedure calls. However, there is no penalty for calling drain() and so it can be included for completeness in all applications.

  2. Call close() to close all of the connections and release any resources associated with the client.