1

尝试序列化预定事件时,我得到

java.io.NotSerializableException: org.quartz.impl.StdScheduler
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at java.util.ArrayList.writeObject(ArrayList.java:710)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)

工作安排如下

    JobDetail job = new JobDetail();

    job.setName(jobName);
    job.setGroup("my group");
    job.setJobClass(Event.class);

    SimpleTrigger trigger = new SimpleTrigger();
    trigger.setStartTime(new Date(momentInTime.inMillis()));
    trigger.setName("trigger" + index);

    if (shouldRunOnce()) {
        trigger.setRepeatCount(0);
    } else {
        trigger.setRepeatInterval(repeatFrequency.inMillis());
        trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    }

    scheduleManager.getScheduler().scheduleJob(job, trigger);

请问这种情况怎么避免?

4

1 回答 1

0

我怀疑您的 Event 类没有实现 Serializable 接口)。
我看不出为什么要序列化调度程序本身,所以我怀疑这就是原因
。这有点道理,因为 Quartz 调度程序必须以某种方式存储作业。

于 2012-11-19T20:06:06.680 回答