Code example for TimeUnit

Methods: sleep, toMillis

0
import java.util.concurrent.TimeUnit; 
 
public class TransactionalMember { 
    public static void main(String[] args)throws Exception {
        HazelcastInstance hz = Hazelcast.newHazelcastInstance();
        TransactionOptions txOptions = new TransactionOptions()
                .setTimeout(10, TimeUnit.SECONDS);
 
        TransactionContext txCxt = hz.newTransactionContext(txOptions);
 
        txCxt.beginTransaction();
        TransactionalMap<String, String> map = txCxt.getMap("map");
 
        try { 
            map.put("1", "1");
            Thread.sleep(TimeUnit.SECONDS.toMillis(20));
            map.put("2", "2");
            txCxt.commitTransaction();
        } catch (RuntimeException t) {
            txCxt.rollbackTransaction();
            throw t;