0 Replies Latest reply on Nov 13, 2006 9:55 PM by Jasper Bryant-Greene

    EJB3 Timer - NotSerializableException

    Jasper Bryant-Greene Newbie

      I'm using EJB3 Timer to schedule retries of failed billing jobs.

      Here's the code that schedules a billing job for retrying:

      public void schedule(@NonNull final Invoice invoice, @NonNull final BillingRetryType type) {
       Calendar twelveHoursFromNow = Calendar.getInstance();
       twelveHoursFromNow.add(Calendar.HOUR, 12);
      
       long everyTwelveHours = 12 * 60 * 60 * 1000;
      
       ctx.getTimerService().createTimer(twelveHoursFromNow.getTime(), everyTwelveHours, new RetryData(invoice, type));
       }


      I get the following exception on the last line of the method:

      13:03:04,124 ERROR [GeneralPurposeDatabasePersistencePlugin] Cannot serialize: nz.co.discountdomains.billing.ejb.RetryData@1cb4598
      java.io.NotSerializableException: java.lang.reflect.Method
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
       at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.serialize(GeneralPurposeDatabasePersistencePlugin.java:365)
       at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.insertTimer(GeneralPurposeDatabasePersistencePlugin.java:184)
       at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:111)
       at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy22.insertTimer(Unknown Source)
       at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:256)
       at org.jboss.ejb3.timerservice.jboss.TimerServiceFacade.createTimer(TimerServiceFacade.java:56)
       at nz.co.discountdomains.billing.ejb.BillingRetryBean.schedule(BillingRetryBean.java:30)


      (Exception snipped to make the post a bit shorter...)

      The RetryData class is simple, it's defined as follows:

      class RetryData implements Serializable {
       private static final long serialVersionUID = 1L;
      
       private Invoice invoice;
       private BillingRetryType type;
      
       public RetryData(Invoice invoice, BillingRetryType type) {
       this.invoice = invoice;
       this.type = type;
       }
      
       public Invoice getInvoice() {
       return invoice;
       }
      
       public BillingRetryType getType() {
       return type;
       }
      }