首先,我安排了5个成功执行的作业(old_job)。之后我安排了另外5个工作(new_job)但是这次前5个工作按照我给新工作的时间表执行了。任何人都可以向我解释redisson的这种行为,并指出我犯了错误。
public class Main {
private final static int NO_OF_JOBS = 5;
public static void main(String[] args) {
Config config = new Config();
config.useClusterServers()
.addNodeAddress("http://127.0.0.1:7000", "http://127.0.0.1:7001", "http://127.0.0.1:7002");
RedissonClient redisson = Redisson.create(config);
RExecutorService e = redisson.getExecutorService("w1");//redisson.getExecutorService("w1");
for (int j = 0; j < NO_OF_JOBS; j++) {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE) + 1;
//System.out.println("hour, minute" + hour + ", " + minute);
((RScheduledExecutorService) e).schedule(new RunnableTask(j + 1), CronSchedule.dailyAtHourAndMinute(hour, minute));
}
}
}
//new_job
public class RunnableTask implements Runnable {
private int job_no;
RunnableTask(int job_no) {
this.job_no = job_no;
}
public void run() {
try {
Thread.sleep(10);
System.out.println("This is task no " + job_no);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//old_Job
public class RunnableTask implements Runnable {
private static volatile int i = 0;
private long anyParam;
public RunnableTask() {
}
RunnableTask(long anyParam) {
this.anyParam = anyParam;
}
public void run() {
try {
Thread.sleep(10);
i++;
System.out.println(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
在本次实验中,我在独立模式下运行了4个redissonnodes,其配置如下所述。
{
"clusterServersConfig":{
"nodeAddresses":[
"redis://127.0.0.1:7001",
"redis://127.0.0.1:7002",
"redis://127.0.0.1:7003"
],
},
"threads":10,
"executorServiceWorkers": {"w1":10},
}
我需要帮助来推断redisson的这种行为。