Copilot commented on code in PR #2475:
URL:
https://github.com/apache/shardingsphere-elasticjob/pull/2475#discussion_r2330286782
##########
kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/LiteJob.java:
##########
@@ -19,20 +19,37 @@
import lombok.Setter;
import org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor;
-import org.quartz.Job;
+import org.quartz.InterruptableJob;
import org.quartz.JobExecutionContext;
+import org.quartz.UnableToInterruptJobException;
+
+import java.util.Objects;
/**
* Lite job.
*/
@Setter
-public final class LiteJob implements Job {
+public final class LiteJob implements InterruptableJob {
private ElasticJobExecutor jobExecutor;
+
+ private volatile Thread currentThread;
Review Comment:
The volatile keyword alone may not provide sufficient thread safety
guarantees for this field. Consider using AtomicReference<Thread> instead to
ensure proper memory visibility and atomic updates in concurrent scenarios.
##########
test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java:
##########
@@ -305,4 +308,44 @@ void testShardingStatisticsAPI() {
});
job.shutdown();
}
+
+ @Test
+ void
testGivenOneShardingCountWhenShutdownThenTaskCanCaptureInterruptedException()
throws Exception {
+ testCaptureInterruptedException(1);
+ }
+
+ @Test
+ void
testGivenOneMoreShardingCountWhenShutdownThenTaskCanCaptureInterruptedException()
throws Exception {
+ testCaptureInterruptedException(2);
+ }
+
+ private void testCaptureInterruptedException(int shardingTotalCount)
throws Exception {
+ String jobName = "testTaskCaptureInterruptedTask";
+ final AtomicBoolean captured = new AtomicBoolean(false);
+ LocalTime tenSecondsLater = LocalTime.now().plusSeconds(2);
+ String cronExpression = String.format("%d %d %d * * ?",
tenSecondsLater.getSecond(), tenSecondsLater.getMinute(),
tenSecondsLater.getHour());
+ SimpleJob captureInterruptedTask = shardingContext -> {
+ try {
+ while (true) {
+ if (Thread.currentThread().isInterrupted()) {
+ captured.set(true);
+ break;
+ }
+ System.out.println("Running...");
Review Comment:
Using System.out.println in test code is not recommended. Consider using a
proper logging framework or removing this debug statement as it may clutter
test output.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]