Code example for ScheduledThreadPoolExecutor

0
  @Autowired 
  InApplicationMonitor inApplicationMonitor;
 
  @Bean 
  public ScheduledExecutorService scheduledExecutorService() {
    ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(schedulerPoolSize);
    setupMonitor(scheduledThreadPoolExecutor);
    return new DelegatingSecurityContextScheduledExecutorService(scheduledThreadPoolExecutor, getSecurityContext());
  } 
 
  public SecurityContext getSecurityContext() { 
    SecurityContext context = SecurityContextHolder.getContext();
    PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(
      METADATA_SCHEDULER + ".user",
      "no credentials", 
      UserAuthorities.USER_AUTHORITIES); 
    authentication.setDetails(new AuthenticationDetails());
    context.setAuthentication(
      authentication);
    return context;