Are callback functions of asynchronous stored-procedure invocation thread safe?
Jan 7, 2011
I'm building the simple application which invokes stored-procedure
asynchronously and sequentially, and want to know whether those
callback functions are thread safe or not.
For example, In the following sample code, the finale value of counter
is guaranteed to be same as the value of total i.e. invocation count
of stored-procedures?
public class Foo { private static long counter; private static class Callback implements ProcedureCallback { @Override public void clientCallback(ClientResponse response) { if (response.getStatus() == ClientResponse.SUCCESS) { this.counter++; } } } public static void main(String[] args) throws Exception { final org.voltdb.client.Client client = ClientFactory.createClient(); client.createConnection("localhost"); final int total = 10000; for (int i = 0; i < total; ++i) { client.callProcedure(callback, "Bar", ); } client.drain(); // assertEquals(this.counter, total); } }
asynchronously and sequentially, and want to know whether those
callback functions are thread safe or not.
For example, In the following sample code, the finale value of counter
is guaranteed to be same as the value of total i.e. invocation count
of stored-procedures?
public class Foo { private static long counter; private static class Callback implements ProcedureCallback { @Override public void clientCallback(ClientResponse response) { if (response.getStatus() == ClientResponse.SUCCESS) { this.counter++; } } } public static void main(String[] args) throws Exception { final org.voltdb.client.Client client = ClientFactory.createClient(); client.createConnection("localhost"); final int total = 10000; for (int i = 0; i < total; ++i) { client.callProcedure(callback, "Bar", ); } client.drain(); // assertEquals(this.counter, total); } }