@Override public boolean unLock() { try { lock.unlock(); } catch (Exception e) { return false; } return true; }
@Override public boolean unLock() { try { lock.unlock(); } catch (Exception e) { return false; } return true; }
private static void executeLock() { System.out.println("### Lock Execution Started... ###"); ILock lock = context.getBean("lock", ILock.class); lock.lock(); System.out.println("lock() call..."); System.out.println("is locked by current thread: " + lock.isLockedByCurrentThread()); lock.unlock(); System.out.println("unlock() call..."); System.out.println("is locked: " + lock.isLocked()); }
@Override protected void doUnregister(URL url) { Set<String> urls = replicatedMap.get(this.nodeId); ILock lock = hazelcastInstance.getLock(nodeId); lock.lock(); try { urls.remove(url.toFullString()); } finally { lock.unlock(); } }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IAtomicLong counter = hz.getAtomicLong("counter"); ILock lock = hz.getLock("lock"); ICondition isOneCondition = lock.newCondition("isOne"); lock.lock(); try { counter.set(1); isOneCondition.signalAll(); } finally { lock.unlock(); } System.out.println("Value changed"); } }
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IAtomicLong counter = hz.getAtomicLong("counter"); ILock lock = hz.getLock("lock"); ICondition isOneCondition = lock.newCondition("isOne"); lock.lock(); try { while (counter.get() != 1) { System.out.println("Waiting"); isOneCondition.await(); } } finally { lock.unlock(); } System.out.println("Wait finished, counter: " + counter.get()); } }
ILock lock = getLock(keyIncrementPair); try { lock.unlock(); localCounter.unlocked++; iterator.remove();
lock.lock(); System.out.println("The lock is locked : " + lock.isLocked()); lock.unlock();
@Override protected void doRegister(URL url) { if (logger.isInfoEnabled()) { logger.info("Register: " + url); } Set<String> urls = replicatedMap.get(nodeId); urls.add(url.toFullString()); ILock lock = hazelcastInstance.getLock(nodeId); lock.lock(); try { replicatedMap.put(nodeId, urls); } finally { lock.unlock(); } }
@Override public void destroy() { try { ILock lock = hazelcastInstance.getLock(nodeId); lock.lock(); try { Set<String> urls = replicatedMap.remove(nodeId); notify(toUrl(urls)); } finally { lock.unlock(); } hazelcastInstance.shutdown(); } catch (Exception e) { logger.warn(e.getMessage()); } }
@SuppressWarnings("unchecked") public ICommandResponse refresh(ILifecycleProgressMonitor monitor) throws SiteWhereException { ILock lock = SiteWhere.getServer().getHazelcastConfiguration().getHazelcastInstance() .getLock(getHazelcastMapName()); try { LOGGER.debug("Locking asset module to load assets from datastore."); lock.lock(); ISearchResults<IAsset> matches = SiteWhere.getServer().getAssetManagement(getTenant()) .listAssets(category.getId(), SearchCriteria.ALL); assets.clear(); for (IAsset asset : matches.getResults()) { assets.put(asset.getId(), (T) asset); } return new CommandResponse(CommandResult.Successful, "Asset list loaded from datastore."); } catch (Throwable t) { return new CommandResponse(CommandResult.Failed, "Asset load operation failed. " + t.getMessage()); } finally { lock.unlock(); LOGGER.debug("Released lock after loading assets from datastore."); } }
@TimeStep public void timeStep(ThreadState state) { firstLock.lock(); try { TransactionContext ctx = targetInstance.newTransactionContext(); try { ctx.beginTransaction(); TransactionalQueue<Integer> queue = ctx.getQueue(name + 'q'); queue.offer(1); secondLock.lock(); secondLock.unlock(); queue.take(); ctx.commitTransaction(); state.counter.committed++; } catch (Exception txnException) { try { ctx.rollbackTransaction(); state.counter.rolled++; logger.severe(name + ": Exception in txn " + state.counter, txnException); } catch (Exception rollException) { state.counter.failedRollbacks++; logger.severe(name + ": Exception in roll " + state.counter, rollException); } } } catch (Exception e) { logger.severe(name + ": outer Exception" + state.counter, e); } finally { firstLock.unlock(); } }
@TimeStep public void timeStep(BaseThreadState state) { int key1 = state.randomInt(maxAccounts); int key2; do { key2 = state.randomInt(maxAccounts); } while (key1 == key2); ILock lock1 = targetInstance.getLock(name + key1); if (lock1.tryLock()) { try { ILock lock2 = targetInstance.getLock(name + key2); if (lock2.tryLock()) { try { IAtomicLong account1 = targetInstance.getAtomicLong(name + key1); IAtomicLong account2 = targetInstance.getAtomicLong(name + key2); int delta = state.randomInt(100); if (account1.get() >= delta) { account1.set(account1.get() - delta); account2.set(account2.get() + delta); } } finally { lock2.unlock(); } } } finally { lock1.unlock(); } } }
networkCreateLock.unlock();
networkCreateLock.unlock();
networkCreateLock.unlock();