code: @Override
      public void close() throws JMSException {
  
          if (closed) {
              return;
          }
  
          /**
           * A message listener must not attempt to close its own connection as
           * this would lead to deadlock.
           */
          if (SQSSession.SESSION_THREAD_FACTORY.wasThreadCreatedWithThisThreadGroup(Thread.currentThread())) {
              throw new IllegalStateException(
                      "MessageListener must not attempt to close its own Connection to prevent potential deadlock issues");
          }
  
          boolean shouldClose = false;
          synchronized (stateLock) {
              if (!closing) {
                  shouldClose = true;
                  closing = true;
              }
          }
  
          if (shouldClose) {
              synchronized (stateLock) {
                  try {
                      for (Session session : sessions) {
                          SQSSession sqsSession = (SQSSession) session;
                          sqsSession.close();
                      }
                      sessions.clear();
                  } finally {
                      closed = true;
                      stateLock.notifyAll();
  
                  }
              }
          }/** Blocks until closing of the connection completes */
          else {
              synchronized (stateLock) {
                  while (!closed) {
                      try {
                          stateLock.wait();
                      } catch (InterruptedException e) {
                          LOG.error("Interrupted while waiting the session to close.", e);
                      }
                  }
              }
          }
  
      }
docs: Closes the connection.
  <P>
  This will not return until all the sessions close internally, which
  blocks until receives and/or message listeners in progress have
  completed.
  <P>
  The receives may return with a message or with null, depending on whether
  there was a message available at the time of the close. If one or more of
  the connection's sessions' message listeners is processing a message at
  the time when connection close is invoked, all the facilities of the
  connection and its sessions must remain available to those listeners
  until they return control to the JMS provider.
  <P>
  A message listener must not attempt to close its own connection;
  otherwise throws a IllegalStateException.
  
  @throws IllegalStateException
  If called by a message listener on its own
  <code>Connection</code>.
  @throws JMSException
  On internal error.