protected void sendPendingPackets(final List<Element> packetsToSend) {
        if (packetsToSend == null || packetsToSend.isEmpty()) {
            return;
        }

        // Schedule in-order.
        synchronized (router) {
            HttpBindManager.getInstance().getSessionManager().execute(this, () -> {
                Log.trace("Stream {}: sending {} packet(s)", streamID, packetsToSend.size());
                for (Element packet : packetsToSend) {
                    try {
                        router.route(packet);
                    } catch (UnknownStanzaException e) {
                        Log.error("On session {} client provided unknown packet type: {}", getStreamID(), packet.asXML(), e);
                    }
                }
            });
        }
    }
This method sends any pending packets in the session. If no packets are
pending, this method simply returns. The method is internally synchronized
to avoid simultaneous sending operations on this Session. If two
threads try to run this method simultaneously, the first one will trigger
the pending packets to be sent, while the second one will simply return
(as there are no packets left to send).
xmppserver/src/main/java/org/jivesoftware/openfire/http/HttpSession.java