Created
December 21, 2016 00:29
-
-
Save khaosans/26af02f5de71b062faf5fa379ab1661c to your computer and use it in GitHub Desktop.
Transaction Map for hazelcast put test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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