Called by MapTransaction, which implicitly holds lock.
428068
void mapPut(S storable) {
        mMap.put(new Key<S>(storable, mFullComparator), storable);
    }
948126
public static void commitTransaction() {
        Connection connection = tl_conn.get();
        if (connection == null) {
            throw new RuntimeException("You do not start a Transaction so you can not commit a transaction!");
        }
        try {
            connection.commit();
            connection.close();
            tl_conn.remove();
            tl_sp.remove();
        } catch (SQLException e) {
            JDBCUtils.rollbackTransaction();
            throw new RuntimeException(e);
        }
    }
841879
void tryUnlockCurrent() {

        if ((m_lockAction != null) && m_lockAction.getChange().equals(CmsLockActionRecord.LockChange.locked)) {
            try {
                A_CmsUI.getCmsObject().unlockResource(m_currentResource);
            } catch (CmsException e) {
                e.printStackTrace();
            }
        }
    }
130584
private void recoverTransactions(AsyncIterator<Map.Entry<TransactionId, Versioned<TransactionInfo>>> iterator, MemberId memberId) {
    iterator.next().thenAccept(entry -> {
      if (entry.getValue().value().coordinator.equals(memberId)) {
        recoverTransaction(entry.getKey(), entry.getValue().value());
      }
      recoverTransactions(iterator, memberId);
    });
  }
1128489
@Override
    public void commit()
    {
        if (!getRollbackOnly())
        {
            onTransaction(TxAction.COMMIT);
            ((EntityManagerImpl) entityManager).getPersistenceDelegator().commit();
        }
    }
173047
public boolean redeliverLocked( TransactionItem[] items , MessageLockSet locks ) throws JMSException
    {
    	checkNotClosed();
    	checkTransactionLock();
    	
    	int volatileRollbacked = 0;
    	int persistentRollbacked = 0;

        synchronized (storeLock)
        {
            for (int n = 0 ; n < items.length ; n++)
            {
            	TransactionItem transactionItem = items[n];
            	if (transactionItem.getDestination() != this)
            		continue; // Not for us
            	
            	MessageStore store = transactionItem.getDeliveryMode() == DeliveryMode.PERSISTENT ? persistentStore : volatileStore;
            	int handle = transactionItem.getHandle();
            	
            	// Retrieve message content
           		AbstractMessage msg = store.retrieve(handle);
           		
           		// Update redelivered flag both in memory and message store
           		msg.setJMSRedelivered(true);
           		handle = store.replace(handle, msg);
           		
            	if (redeliveryDelay > 0)
            	{
            	    // Keep the message locked so it cannot be re-consumed immediately            	    
            		// and schedule message unlock after redeliveryDelay milliseconds
            		redeliveryTimer.schedule(new RedeliveryTask(msg,store,handle), 
            				                 redeliveryDelay);
            	}
            	else
            	{
            		// Store lock for later release
            		locks.add(handle, store.getDeliveryMode(), this, msg);
            	}

                if (transactionItem.getDeliveryMode() == DeliveryMode.PERSISTENT)
                	persistentRollbacked++;
                else
                	volatileRollbacked++;
            }
        }
        rollbackedGetCount.addAndGet(volatileRollbacked + persistentRollbacked);

        if (persistentRollbacked > 0 && requiresTransactionalUpdate())
        {
        	pendingChanges = true;
        	return true;
        }
        else
        	return false;
    }
300087
public final void release(TotalOrderRemoteTransactionState state) {
      TotalOrderLatch synchronizedBlock = state.getTransactionSynchronizedBlock();
      if (synchronizedBlock == null) {
         //already released!
         return;
      }
      Collection<Object> lockedKeys = state.getLockedKeys();
      synchronizedBlock.unBlock();
         for (Object key : lockedKeys) {
            keysLocked.remove(key, synchronizedBlock);
         }
      if (trace) {
         log.tracef("Release %s and locked keys %s. Checking pending tasks!", synchronizedBlock, lockedKeys);
      }
      state.reset();
   }
139444
public void runInTransaction(Runnable runnable)
    throws DataAccessException {
        TransactionWrapper transaction=null;
        try {
            transaction = startTransaction();
            runnable.run();
        } finally {
            stopTransaction(transaction);
        }
    }
138045
public void runInRetryableTransaction(Runnable runnable)
    throws DataAccessException {
        TransactionWrapper transaction=null;
        try {
            transaction = startTransaction();
            runnable.run();
        } catch (Throwable e) {
            if (canRetryTransaction(e)) {
                transaction = (TransactionWrapper)initTransactionRetry(transaction);
                ((ProcessExecutor)getTransactionRetrier()).runInTransaction(runnable);
            }
            else
                throw e;
        } finally {
            stopTransaction(transaction);
        }
    }
793723
void close() throws RepositoryException {
        mLock.lock();
        if (mClosed) {
            mLock.unlock();
            return;
        }
 
        Map<Class<?>, CursorList<TransactionImpl<Txn>>> cursors;
        try {
            cursors = mCursors;        

            // Ensure that map is freed promptly. Thread-local reference to
            // this scope otherwise keeps map and its contents lingering around
            // for a very long time.
            mCursors = null;

            while (mActive != null) {
                mActive.exit();
            }
        } finally {
            // Swap TransactionManager out with a dummy one, to allow the
            // original one to get freed.
            mTxnMgr = (TransactionManager<Txn>) TransactionManager.Closed.THE;
            mClosed = true;
            mLock.unlock();
        }

        // Close cursors without lock held, to prevent deadlock. Cursor close
        // operation might acquire its own lock, which in turn acquires a lock
        // on this scope.
        if (cursors != null) {
            for (CursorList<TransactionImpl<Txn>> cursorList : cursors.values()) {
                cursorList.closeCursors();
            }
        }
    }
10738
private void commitTransaction() {
        Tenant tenant = Tenant.getTenant(m_tableDef);
        DBTransaction dbTran = DBService.instance(tenant).startTransaction();
        m_parentTran.applyUpdates(dbTran);
        DBService.instance(tenant).commit(dbTran);
        m_parentTran.clear();
    }
1212076
void detach() {
        mLock.lock();
        try {
            if (mDetached || mTxnMgr.removeLocalScope(this)) {
                mDetached = true;
            } else {
                throw new IllegalStateException("Transaction is attached to a different thread");
            }
        } finally {
            mLock.unlock();
        }
    }
997889
@Override
    public void lock(Object entity, LockModeType lockMode)
    {
        ivEm.lock(entity, lockMode);
    }
986963
public void startTransaction()
   {
      Long key = Long.valueOf(Thread.currentThread().getId());
      TransactionImpl tx = txs.get(key);

      if (tx == null)
      {
         TransactionImpl newTx = new TransactionImpl(key);
         tx = txs.putIfAbsent(key, newTx);
         if (tx == null)
            tx = newTx;
      }

      tx.active();
   }
658215
public final void ensureOrder(TotalOrderRemoteTransactionState state, Collection<?> keysModified) throws InterruptedException {
      //the retries due to state transfer re-uses the same state. we need that the keys previous locked to be release
      //in order to insert it again in the keys locked.
      //NOTE: this method does not need to be synchronized because it is invoked by a one thread at the time, namely
      //the thread that is delivering the messages in total order.
      state.awaitUntilReset();
      TotalOrderLatch transactionSynchronizedBlock = new TotalOrderLatchImpl(state.getGlobalTransaction().globalId());
      state.setTransactionSynchronizedBlock(transactionSynchronizedBlock);
         //this will collect all the count down latch corresponding to the previous transactions in the queue
         for (Object key : keysModified) {
            TotalOrderLatch prevTx = keysLocked.put(key, transactionSynchronizedBlock);
            if (prevTx != null) {
               state.addSynchronizedBlock(prevTx);
            }
            state.addLockedKey(key);

      }

      TotalOrderLatch stateTransfer = stateTransferInProgress.get();
      if (stateTransfer != null) {
         state.addSynchronizedBlock(stateTransfer);
      }

      if (trace) {
         log.tracef("Transaction [%s] will wait for %s and locked %s", state.getGlobalTransaction().globalId(),
                    state.getConflictingTransactionBlocks(), state.getLockedKeys() == null ? "[ClearCommand]" :
               state.getLockedKeys());
      }
   }
563580
private void lock(Object obtainer) throws PSQLException {
    if (lockedFor == obtainer) {
      throw new PSQLException(GT.tr("Tried to obtain lock while already holding it"),
          PSQLState.OBJECT_NOT_IN_STATE);

    }
    waitOnLock();
    lockedFor = obtainer;
  }
550746
public synchronized void locking(Context ctxt, ILexLocation location)
	{
		// Enter a locking state - called by thread
		waitUntilState(RunState.LOCKING, RunState.RUNNING, ctxt, location);
	}