code: private TimerTask getTask(){
          TimerTask checkForRestartTask = new TimerTask() {
              @Override
              public void run() {
                  if (lastPongAt == 0) return;
  
                  Date currentDate = new Date();
                  long timeInterval = (currentDate.getTime() - lastPongAt);
                  if (timeInterval >= 2 * pingInterval) {
                      doReconnect();
                  }
              }
          };
          return checkForRestartTask;
      }
docs: Returns task which performs check every second for reconnection.
  @return TimerTask returns timer task which will be invoked after user defined interval and tries reconnect.