Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Executor not serializable? won't work in MapTrigger.

snidely_whiplashJul 17 2009 — edited Jul 21 2009
I have a MapTrigger below which seems to work. I want to change it to use an Executor instead of creating a new thread every time it runs.
public class ExecutionMapTrigger implements MapTrigger {

    public ExecutionMapTrigger() {
    }

    PositionFillProcessor positionFillProc = new PositionFillProcessor();

    public void process(MapTrigger.Entry entry) {
        final Execution e = (Execution)entry.getValue();

        new Thread(new Runnable() {
                public void run() {
                    Position.connectToCache();
                    PositionKey positionKey = new PositionKey(e.getSymbol(), e.getAccount());
                    System.out.println("locking=" + Position.cache.lock(positionKey, -1));
                    if (!Position.cache.containsKey(positionKey)) {
                        System.out.println("\tNEW position: " + e.getAccount() + " " + e.getSymbol());
                        Position p = new Position();
                        p.setSymbol(e.getSymbol());
                        p.setAccount(e.getAccount());
                        Position.cache.put(positionKey, p);
                    } else {
                        System.out.println("\tEXISTING position: " + e.getAccount() + " " + e.getSymbol() + " " +
                                           Position.cache.get(positionKey));
                    }
                    positionFillProc.setExecution(e);
                    Position.cache.invoke(positionKey, positionFillProc);
                    System.out.println("\tFILLED position: " + (Position)Position.cache.get(positionKey));
                    System.out.println("unlocking");
                    Position.cache.unlock(positionKey);
                }
            }).start();
    }

    // ---- hashCode() and equals() must be implemented

    public boolean equals(Object o) {
        return o != null && o.getClass() == this.getClass();
    }

    public int hashCode() {
        return getClass().getName().hashCode();
    }
}
When I add to my MapTrigger the line:
ExecutorService threadExecutor = Executors.newFixedThreadPool( 4 );
I get....
Exception in thread "main" (Wrapped: Failed request execution for DistributedCache service on Member(Id=1, Timestamp=2009-07-17 14:52:42.409, Address=192.168.10.167:8088, MachineId=25255, Location=machine:box2,process:61328, Role=CoherenceServer)) java.io.InvalidClassException: oms.ExecutionMapTrigger; local class incompatible: stream classdesc serialVersionUID = -4646108391876591121, local class serialVersionUID = -5632005111953002250
	at com.tangosol.util.Base.ensureRuntimeException(Base.java:293)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.tagException(Grid.CDB:36)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache.onListenerRequest(DistributedCache.CDB:53)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ListenerRequest.onReceived(DistributedCache.CDB:1)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:9)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:136)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache.onNotify(DistributedCache.CDB:3)
	at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.InvalidClassException: oms.ExecutionMapTrigger; local class incompatible: stream classdesc serialVersionUID = -4646108391876591121, local class serialVersionUID = -5632005111953002250
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
	at com.tangosol.util.ExternalizableHelper.readSerializable(ExternalizableHelper.java:2135)
	at com.tangosol.util.ExternalizableHelper.readObjectInternal(ExternalizableHelper.java:2262)
	at com.tangosol.util.ExternalizableHelper.readObject(ExternalizableHelper.java:2209)
	at com.tangosol.io.DefaultSerializer.deserialize(DefaultSerializer.java:60)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.Service.readObject(Service.CDB:4)
	at com.tangosol.coherence.component.net.Message.readObject(Message.CDB:1)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ListenerRequest.read(DistributedCache.CDB:10)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:123)
	... 3 more
2009-07-17 14:52:51.145/1.731 Oracle Coherence GE 3.5/459 <D4> (thread=ShutdownHook, member=2): ShutdownHook: stopping cluster node
2009-07-17 14:52:51.145/1.731 Oracle Coherence GE 3.5/459 <D5> (thread=Cluster, member=2): Service Cluster left the cluster
Is the Executor not serializable or something? is there a better way to do this?

Thanks,
Andrew
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2009
Added on Jul 17 2009
4 comments
1,880 views