28 Kasım 2023 Salı

SpringScheduling Shedlock KeepAliveLockProvider Sınıfı

Giriş
Şu satırı dahil ederiz
import net.javacrumbs.shedlock.support..KeepAliveLockProvider;
Açıklaması şöyle
KeepAliveLockProvider extends the lock in the middle of the lockAtMostFor interval. For example, if the lockAtMostFor is 10 minutes the lock is extended every 5 minutes for 10 minutes until the lock is released. Please note that the minimal lockAtMostFor time supported by this provider is 30s. The scheduler is used only for the lock extension, single thread should be enough.
Örnek
Şöyle yaparız
@Configuration
public class ShedlockConfiguration {

  @Bean
  public LockProvider lockProvider(DataSource dataSource) {
    return new KeepAliveLockProvider(
      getJdbcTemplateLockProvider(dataSource),
      Executors.newSingleThreadScheduledExecutor()
    );
  }

  private JdbcTemplateLockProvider getJdbcTemplateLockProvider(DataSource dataSource) {
    return new JdbcTemplateLockProvider(
      JdbcTemplateLockProvider.Configuration.builder()
        .withJdbcTemplate(new JdbcTemplate(dataSource))
        .withDbUpperCase(true)
        .usingDbTime()
        .build()
      );
  }
}




Hiç yorum yok:

Yorum Gönder