title: Why does the scheduler kill my shuffling algorithm?
body: <p>I came up with this algorithm for shuffling random users to another users. (for secret santa game) But when I start async process for shuffling at given time it stops by the 5th user. Any ideas why?</p>
  
  <p>My service for the algorithm and starting it :</p>
  
  <pre><code>public class GitfteeServiceImpl implements GifteeService{
  @Autowired
  private  UserRepository userRepository;
  
  private final ScheduledExecutorService shufflingScheduler = Executors.newSingleThreadScheduledExecutor();
  
  @Override
  public void setGifteeToAll() {
      List&lt;User&gt; users = userRepository.findAll();
      List&lt;User&gt; usersGiftees = userRepository.findAll();
      List&lt;Long&gt; userIds = usersGiftees.stream().map(User::getUserId).collect(Collectors.toList());
      log.info(users.toString());
      for(User u : users){
          User giftee = getGifteeForOne(u, usersGiftees,userIds);
          userIds.remove(giftee.getUserId());
          usersGiftees.remove(giftee);
      }
  }
  
  private User getGifteeForOne(User user, List&lt;User&gt; users, List&lt;Long&gt; ids) {
      Long randomId = getRandomId(ids);
      User giftee = userRepository.findByUserId(randomId);
  
      while (giftee == null || !users.contains(giftee) || Objects.equals(user.getUserId(), randomId)){
          randomId = getRandomId(ids);
          giftee = userRepository.findByUserId(randomId);
      }
  
      user.setGiftee(giftee);
      userRepository.save(user);
      return giftee;
  }
  
  private Long getRandomId(List&lt;Long&gt; ids) {
      Collections.shuffle(ids);
      return ids.get(0);
  }
  
  @Override
  public void scheduleShuffling(LocalDateTime gameDuration) {
      Runnable scheduleShufflingTask = this::setGifteeToAll;
      Duration duration = Duration.between(LocalDateTime.now(), gameDuration);
      shufflingScheduler.schedule(scheduleShufflingTask, duration.getSeconds(), TimeUnit.SECONDS);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my controller:</p>
  
  <pre><code>public class AdminController {
  
  @Autowired
  GifteeService gifteeService;
  
  @PostMapping("/start_date")
  public void hi(@RequestBody LocalDateTime localDateTime) {
      LocalDateTime aDateTime = LocalDateTime.of(2019, Month.JANUARY, 17, 22, 39, 50);
      gifteeService.scheduleShuffling(aDateTime);
  
  }
  </code></pre>