src/main/java/org/jivesoftware/smack/keepalive/KeepAliveManager.java
private synchronized void schedulePingServerTask() {
        enableExecutorService();
        stopPingServerTask();

        if (pingInterval > 0) {
            periodicPingTask = periodicPingExecutorService.schedule(
                    new Runnable() {
                        @Override
                        public void run() {
                            Ping ping = new Ping();
                            PacketFilter responseFilter = new PacketIDFilter(
                                    ping.getID());
                            Connection connection = weakRefConnection.get();
                            final PacketCollector response = pingFailedListeners
                                    .isEmpty() ? null : connection
                                    .createPacketCollector(responseFilter);
                            connection.sendPacket(ping);

                            if (response != null) {
                                // Schedule a collector for the ping reply,
                                // notify listeners if none is received.
                                periodicPingExecutorService.schedule(
                                        new Runnable() {
                                            @Override
                                            public void run() {
                                                Packet result = response
                                                        .nextResult(1);

                                                // Stop queuing results
                                                response.cancel();

                                                // The actual result of the
                                                // reply can be ignored since we
                                                // only care if we actually got
                                                // one.
                                                if (result == null) {
                                                    for (PingFailedListener listener : pingFailedListeners) {
                                                        listener.pingFailed();
                                                    }
                                                }
                                            }
                                        }, SmackConfiguration
                                                .getPacketReplyTimeout(),
                                        TimeUnit.MILLISECONDS);
                            }
                        }
                    }, getPingInterval(), TimeUnit.MILLISECONDS);
        }
    }
private synchronized void schedulePingServerTask() {
        enableExecutorService();
        stopPingServerTask();

        if (pingInterval > 0) {
            periodicPingTask = periodicPingExecutorService.schedule(
                    new Runnable() {
                        @Override
                        public void run() {
                            Ping ping = new Ping();
                            PacketFilter responseFilter = new PacketIDFilter(
                                    ping.getID());
                            Connection connection = weakRefConnection.get();
                            final PacketCollector response = pingFailedListeners
                                    .isEmpty() ? null : connection
                                    .createPacketCollector(responseFilter);
                            connection.sendPacket(ping);

                            if (response != null) {
                                // Schedule a collector for the ping reply,
                                // notify listeners if none is received.
                                periodicPingExecutorService.schedule(
                                        new Runnable() {
                                            @Override
                                            public void run() {
                                                Packet result = response
                                                        .nextResult(1);

                                                // Stop queuing results
                                                response.cancel();

                                                // The actual result of the
                                                // reply can be ignored since we
                                                // only care if we actually got
                                                // one.
                                                if (result == null) {
                                                    for (PingFailedListener listener : pingFailedListeners) {
                                                        listener.pingFailed();
                                                    }
                                                }
                                            }
                                        }, SmackConfiguration
                                                .getPacketReplyTimeout(),
                                        TimeUnit.MILLISECONDS);
                            }
                        }
                    }, getPingInterval(), TimeUnit.MILLISECONDS);
        }
    }
private synchronized void schedulePingServerTask ( ) { enableExecutorService ( ) ; stopPingServerTask ( ) ; if ( pingInterval > 0 ) { periodicPingTask = periodicPingExecutorService . schedule ( new Runnable ( ) { @ Override public void run ( ) { Ping ping = new Ping ( ) ; PacketFilter responseFilter = new PacketIDFilter ( ping . getID ( ) ) ; Connection connection = weakRefConnection . get ( ) ; final PacketCollector response = pingFailedListeners . isEmpty ( ) ? null : connection . createPacketCollector ( responseFilter ) ; connection . sendPacket ( ping ) ; if ( response != null ) { // Schedule a collector for the ping reply, // notify listeners if none is received. periodicPingExecutorService . schedule ( new Runnable ( ) { @ Override public void run ( ) { Packet result = response . nextResult ( 1 ) ; // Stop queuing results response . cancel ( ) ; // The actual result of the // reply can be ignored since we // only care if we actually got // one. if ( result == null ) { for ( PingFailedListener listener : pingFailedListeners ) { listener . pingFailed ( ) ; } } } } , SmackConfiguration . getPacketReplyTimeout ( ) , TimeUnit . MILLISECONDS ) ; } } } , getPingInterval ( ) , TimeUnit . MILLISECONDS ) ; } }
Cancels any existing periodic ping task if there is one and schedules a
new ping task if pingInterval is greater then zero.

This is designed so only one executor is used for scheduling all pings on
all connections. This results in only 1 thread used for pinging.
Cancels any existing periodic ping task if there is one and schedules a new ping task if pingInterval is greater then zero .