/** Changes the state to idle. */
  void toIdle() {
    if (_shareHead != null) return;
    else if (_xid != null || _isLocalTransaction) return;
    else if (_hasConnectionError) {
      destroy();
      return;
    }

    UserTransactionImpl transaction = _transaction;
    _transaction = null;

    if (transaction != null) {
      try {
        transaction.delistPoolItem(this, XAResource.TMSUCCESS);
      } catch (Throwable e) {
        log.log(Level.FINE, e.toString(), e);
      }
    }

    _isLocalTransaction = false;

    if (log.isLoggable(Level.FINE)) log.fine("idle " + this);

    _poolEventTime = Alarm.getCurrentTime();
    _cm.toIdle(this);
  }