Skip to content

Instantly share code, notes, and snippets.

@khaosans
Created December 21, 2016 00:29
Show Gist options
  • Save khaosans/26af02f5de71b062faf5fa379ab1661c to your computer and use it in GitHub Desktop.
Save khaosans/26af02f5de71b062faf5fa379ab1661c to your computer and use it in GitHub Desktop.
Transaction Map for hazelcast put test
public static void main(String[] args) throws InterruptedException {
ClientConfig clientConfig = new ClientConfig();
List addressList = new ArrayList();
addressList.add("localhost:5701");
clientConfig.getNetworkConfig().setAddresses(addressList).setConnectionAttemptLimit(1000).setRedoOperation(true);
HazelcastInstance hazelcasetInstance = HazelcastClient.newHazelcastClient(clientConfig);
for (int i = 0; i < 10000; i++) {
try {
TransactionOptions options = new TransactionOptions()
.setTransactionType(TransactionOptions.TransactionType.TWO_PHASE);
TransactionContext context = hazelcasetInstance.newTransactionContext(options);
context.beginTransaction();
TransactionalMap<String, String> map = context.getMap("map");
System.out.println(i);
map.put(Integer.toString(i), "test");
Thread.sleep(1000);
try {
context.commitTransaction();
} catch (Exception e) {
context.rollbackTransaction();
}
} catch (Exception e) {
}
}
hazelcasetInstance.shutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment