问题标签 [shedlock]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
4614 浏览

java - 如何用编程风格替换@SchedulerLock

我使用spring boot,在代码中的某处我有以下代码:

有没有办法通过编程风格替换它?

0 投票
1 回答
1286 浏览

java - Shedlock:使用属性文件中的 lockAtMostForString

我有这样的代码:

现在我使用常量,lockAtMostForString但我想从属性中获取这个值。
有办法吗?

附言

我知道我不能使用注释并像这样重写它:

但我更喜欢使用注释。

0 投票
1 回答
931 浏览

java - 如何理解 shedlock 何时被获取和释放?

我有这样的代码:

我有 2 个节点。根据日志,我看到task()仅在第一个节点上有效的情况。在第二个节点上我只看到Spring scheduler started task, awaiting shedlock

我认为它不应该以这种方式工作,我想调查它为什么会发生。

锁定释放时如何订阅事件?

shedlock 尝试获取锁多长时间?

附言

someInterval = 30 分钟

lockConfiguration: atleast = 5 min, atMost=20min

0 投票
1 回答
2622 浏览

java - 如何修复 Spring Boot 应用程序中的 Websockets 和 Shedlock 兼容性

我有一个使用带有 SockJS 的 Websockets 的 Spring Boot 实时应用程序。目前我正在使用 LoadBalancer 和两个实例扩展我的应用程序。由于应用程序中的 cron 作业很少,我需要在两台服务器之间同步它,以便一次只运行一项任务。为此,我使用了 shedlock-spring 和 shedlock-provider-hazelcast 依赖项(我也在应用程序中使用 Hazelcast)。

如果我@EnableSchedulerLock(defaultLockAtMostFor = "PT1S")向应用程序添加注释MainApplication.class由于以下错误而无法启动:

@SchedulerLock注释工作正常,因为我在单独的应用程序中对其进行了测试,但它似乎与 Websockets 冲突并覆盖了一些 bean。我是 Websockets 配置的新手,所以如果有人知道此错误的原因以及如何修复它,请提供帮助。

这是我完美运行的 Websocket 配置:

0 投票
1 回答
857 浏览

spring - SpringBootTest 因“IllegalStateException - 未设置 ServletContext”而失败

我有一个非常简单的@SpringBootTest

在我们在文件中添加@EnableSchedulerLock(来自Shedlock)之前,它按预期工作MyApplication.java

因为,我们遇到了这个问题:

当 Spring 尝试实例化它时,就会发生这种情况resourceHandlerMapping

这就像在调用(from )@Bean之前创建的。setServletContextWebMvcConfigurationSupport

0 投票
3 回答
5616 浏览

java - 带有锁的 Spring 引导计划任务未因延迟而运行

我正在使用带有 shedlock 的 spring boot 来确保我的计划任务只能同时在一个实例中运行。

这是我的配置

这是我的任务

这是 shedlock 表 NAME LOCK_UNTIL LOCKED_AT LOCKED_BY

这里的问题是,当我的任务在 03-JUL-19 06.37.55.858685000 PM 第一次运行时

Shedlock 将向 DB 中添加 1 行,如下所示:

因为 defaultLockAtMostFor 是 15 分钟

任务完成后,会更新这条记录解锁,现在的行是:

因为 defaultLockAtLeastFor 是 2 分钟。

当到下一次运行任务(2019-07-03T18:37:58.434650900Z)时,它将通过sql命令更新记录以获取锁定

无法更新,因此任务不会运行。

在这里,我必须等待大约 2 分钟,直到当前时间结束 LOCK_UNTIL (03-JUL-19 06.39.37.178573000 PM),而我的任务配置了 2 秒延迟所以我的任务不会按预期每 2 秒运行一次,而是它将运行每 2 分钟。

0 投票
0 回答
827 浏览

java - org.springframework.orm.ObjectOptimisticLockingFailureException 在一个事务方法中,在 Spring 作业中具有 shedlock 和 hibernate

org.springframework.orm.ObjectOptimisticLockingFailureException在 Spring Boot 2.1 服务中得到了很多。我在 Spring's 有一份工作@Scheduled,我在带有 Hibernate 的 PostgreSQL 中保存的地址不多。

延迟设置为fixedDelay = 5000L, initialDelay = 5000L。我使用net.javacrumbs.shedlock,所以锁被持久化在数据库中,只有一个容器会获取锁并调用publishBatch()

它看起来像这样:

堆栈跟踪的一部分:

我尝试不保存每个地址,而是收集列表然后调用saveAll(). 另外我读到这可能是一个冲洗问题,但我无法测试它,因为我没有得到EntityManager并且找不到手动冲洗的方法。另外我认为它应该被正确处理,如果它是事务性的。

谢谢!

问候

0 投票
2 回答
2844 浏览

spring-boot - 使用ShedLock让ThreadPoolTask​​Scheduler处理多个调度任务的分布式锁问题

我知道 ShedLock 可以用来做与 Spring 集成的分布式锁:

但就我而言,我想执行从数据库中读取的多个计划任务(Crons),并由 ThreadPoolTask​​Scheduler 分别独立地进行处理。我编码如下,但是它不能处理多个实例来执行每个计划任务。Spring有没有办法实现这一点?任何想法将不胜感激。

0 投票
1 回答
1124 浏览

java - spring-boot 和 shedlock - 如何追踪依赖冲突?

我需要在使用 shedlock 的微服务项目中更新 spring-boot 的次要版本。

如果 spring-boot 是 2.0.x 版本,它可以正常工作,但如果我将它升级到 2.1.x,测试应用程序 maven 构建会中断并给我这个输出。

Maven依赖树是:

ibl:oaa:war:0.0.8-RELEASE

+- ibl:domain:jar:0.0.6-SNAPSHOT:compile | - com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.7:compile | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
| - com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile

+- org.springframework.boot:spring-boot-starter:jar:2.1.1.RELEASE:compile | +- org.springframework.boot:spring-boot:jar:2.1.1.RELEASE:compile
| +- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.1.RELEASE:compile | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
| +- org.springframework:spring-core:jar:5.1.3.RELEASE:compile
| | - org.springframework:spring-jcl:jar:5.1.3.RELEASE:compile
| - org.yaml:snakeyaml:jar:1.23:compile

+- com.oracle:ojdbc6:jar:11.2.0:compile
+- org.springframework.boot:spring-boot-starter-web:jar:2.1.1.RELEASE:compile | +- org.springframework.boot:spring-boot-starter-json:jar:2.1.1.RELEASE:compile | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.7:compile | | - com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.7:compile | +- org.hibernate.validator:hibernate-validator:jar:6.0.13.Final:compile
| | +- javax.validation:validation-api:jar:2.0.1.Final:compile
| | - org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
| +- org.springframework:spring-web:jar:5.1.3.RELEASE:compile
| | - org.springframework:spring-beans:jar:5.1.3.RELEASE:compile
| - org.springframework:spring-webmvc:jar:5.1.3.RELEASE:compile
| +- org.springframework:spring-aop:jar:5.1.3.RELEASE:compile
| - org.springframework:spring-expression:jar:5.1.3.RELEASE:compile

+- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.1.RELEASE:provided | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.13:provided
| +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.13:provided
| - org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.13:provided

+- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.1.RELEASE:compile | +- com.zaxxer:HikariCP:jar:3.2.0:compile
| - org.springframework:spring-jdbc:jar:5.1.3.RELEASE:compile
| - org.springframework:spring-tx:jar:5.1.3.RELEASE:compile

+- org.springframework.boot:spring-boot-starter-actuator:jar:2.1.1.RELEASE:compile | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.1.1.RELEASE:compile | | - org.springframework.boot:spring-boot-actuator:jar:2.1.1.RELEASE:compile | - io.micrometer:micrometer-core:jar:1.1.1:compile
| +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
| - org.latencyutils:LatencyUtils:jar:2.0.3:compile

+- org.springframework.boot:spring-boot-starter-test:jar:2.1.1.RELEASE:compile | +- org.springframework.boot:spring-boot-test:jar:2.1.1.RELEASE:compile
| +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.1.RELEASE:compile | +- com.jayway.jsonpath:json-path:jar:2.4.0:compile
| | -net.minidev:json-smart:jar:2.3:compile
| | -net.minidev:accessors-smart:jar:1.2:compile
| | - org.ow2.asm:asm:jar:5.0.4:compile
| +- junit:junit:jar:4.12:compile
| +- org.assertj:assertj-core:jar:3.11.1:compile
| +- org.hamcrest:hamcrest-core:jar:1.3:compile
| +- org.hamcrest:hamcrest-library:jar:1.3:compile
| +- org.skyscreamer:jsonassert:jar:1.5.0:compile
| | - com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:compile | +- org.springframework:spring-test:jar:5.1.3.RELEASE:compile
| - org.xmlunit:xmlunit-core:jar:2.6.2:compile

+- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.1.RELEASE:compile | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.1:compile
| | - org.apache.logging.log4j:log4j-api:jar:2.11.1:compile
| +- org.apache.logging.log4j:log4j-core:jar:2.11.1:compile
| +- org.apache.logging.log4j:log4j-jul:jar:2.11.1:compile
| - org.slf4j:jul-to-slf4j:jar:1.7.25:compile

+- org.apache.httpcomponents:httpclient:jar:4.5.6:compile | +- commons-logging:commons-logging:jar:1.2:compile
| - commons-codec:commons-codec:jar:1.10:compile

+- org.apache.httpcomponents:httpcore:jar:4.4.10:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.9.7:compile | - com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile

+- io.springfox:springfox-swagger2:jar:2.9.2:compile | +- io.swagger:swagger-annotations:jar:1.5.20:compile
| +- io.swagger:swagger-models:jar:1.5.20:compile
| +- io.springfox:springfox-spi:jar:2.9.2:compile
| | - io.springfox:springfox-core:jar:2.9.2:compile
| +- io.springfox:springfox-schema:jar:2.9.2:compile
| +- io.springfox:springfox-swagger-common:jar:2.9.2:compile
| +- io.springfox:springfox-spring-web:jar:2.9.2:compile
| +- com.google.guava:guava:jar:20.0:compile
| +- com.fasterxml:classmate:jar:1.4.0:compile
| +- org.slf4j:slf4j-api:jar:1.7.25:compile
| +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile | +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile | - org.mapstruct:mapstruct:jar:1.2.0.Final:compile

+- io.springfox:springfox-swagger-ui:jar:2.9.2:compile
+- org.projectlombok:lombok:jar:1.18.4:compile
+- org.apache.commons:commons-lang3:jar:3.8。 1: 编译
+- com.h2database:h2:jar:1.4.197: 编译
+- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.1.1.RELEASE:compile | +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.1.RELEASE:compile | | - org.aspectj:aspectjweaver:jar:1.9.2:compile
| +- javax.transaction:javax.transaction-api:jar:1.3:compile
| +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
| | - javax.activation:javax.activation-api:jar:1.2.0:compile
| +- org.hibernate:hibernate-core:jar:5.3.7.Final:compile
| | +- javax.persistence:javax.persistence-api:jar:2.2:compile
| | +- org.javassist:javassist:jar:3.23.1-GA:compile
| | +- antlr:antlr:jar:2.7.7:compile
| | +- org.jboss:jandex:jar:2.0.5.Final:compile
| | +- org.dom4j:dom4j:jar:2.1.1:compile
| | - org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile | +- org.springframework.data:spring-data-jpa:jar:2.1.3.RELEASE:compile
| | +- org.springframework.data:spring-data-commons:jar:2.1.3.RELEASE:compile | | - org.springframework:spring-orm:jar:5.1.3.RELEASE:compile
| - org.springframework:spring-aspects:jar:5.1.3.RELEASE:compile

+- org.mockito:mockito-core:jar:2.21.0:compile | +- net.bytebuddy:byte-buddy:jar:1.8.15:compile
| +- net.bytebuddy:byte-buddy-agent:jar:1.8.15:compile
| - org.objenesis:objenesis:jar:2.6:compile

+- commons-io:commons-io:jar:2.6:compile
+- org.powermock:powermock-module-junit4:jar:2.0.0:test | -org.powermock:powermock-module-junit4-common:jar:2.0.0:test
| +- org.powermock:powermock-reflect:jar:2.0.0:test
| - org.powermock:powermock-core:jar:2.0.0:test

+- org.powermock:powermock-api-mockito2:jar:2.0.0:test | - org.powermock:powermock-api-support:jar:2.0.0:test

+- net.javacrumbs.shedlock:shedlock-spring:jar:2.5.0:compile | +- net.javacrumbs.shedlock:shedlock-core:jar:2.5.0:compile
| - org.springframework:spring-context:jar:5.0.6.RELEASE:compile

+- net.javacrumbs.shedlock:shedlock-provider-jdbc-template:jar:2.5.0:compile | -net.javacrumbs.shedlock:shedlock-provider-jdbc-internal:jar:2.5.0:compile -javax.mail:mail:jar:1.4:compile
-javax.activation:activation:jar:1.1:compile

并且pom.xml是:

我将此发布到 ShedLock 问题页面,他们说这更有可能是依赖冲突的问题,而不是 ShedLock 的问题。

我怎样才能解决这个问题?

0 投票
1 回答
2717 浏览

quartz-scheduler - 用于锁定 Quartz 调度程序的 Shedlock

我正在为我的计划任务寻找锁定解决方案。我不能使用内置的 Quartz 机制,因为我没有使用 JDBC。我遇到了 Shedlock,但它似乎与 Spring Scheduler 紧密集成。我还遇到了https://www.baeldung.com/shedlock-spring,这表明它是 Quartz 的替代品。我的理解是否正确,它不是与 Quartz 调度程序一起使用的好选择?

提前致谢。