private void removeDevices(String[] devices) {
    EntityManager mgr = null;

    // Skip removing devices that have been registered very recently
    // as the request to remove them may be obsolete
    Calendar removalThreshold = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    removalThreshold.add(Calendar.HOUR, FRESH_REGISTRATION_TIME_WINDOW_IN_HOURS);
    Date removalThresholdDate = removalThreshold.getTime();

    try {
      mgr = getEntityManager();

      for (String deviceToken : devices) {
        DeviceRegistration deviceEntity = mgr.find(DeviceRegistration.class, deviceToken);

        // Remove the registration if it hasn't been already removed or recently (re-)registered.
        if (deviceEntity != null && removalThresholdDate.after(deviceEntity.getTimestamp())) {
          mgr.getTransaction().begin();
          mgr.remove(deviceEntity);
          mgr.getTransaction().commit();
        }
      }
    } finally {
      if (mgr != null && mgr.isOpen()) {
        mgr.close();
      }
    }
  }