vvekselva
vvekselva

Reputation: 823

Oracle Coherence

I'm new to Oracle Coherence. I read the documentation and done the hands-on using the command prompt. I've no issues in understanding. Then I downloaded the eclipse with oracle coherence tools. I created the application client for the oracle coherence as given below http://docs.oracle.com/cd/E18686_01/coh.37/e18692/installjdev.htm

I ran the same. It was working fine as I did in my console application. Then I created a new project in the same workspace, created a main class accessed the named cache, put and retrieved some values using the below code,

package coherenceClient;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class Main {
    public static void main(String[] args) {

        NamedCache cache = CacheFactory.getCache("myCache");

        cache.put("MyFirstCacheObject", "This is my first Cache Object");

        System.out.println(cache.get("MyFirstCacheObject"));
    }
}

I retieved the same value. Then I created another class tried retrieved the same value but it was returning null. Is there are any mistakes in the code?

package coherenceClient;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class Recevier {
public static void main(String[] args) {

    NamedCache cache = CacheFactory.getCache("myCache");
    System.out.println(cache.get("MyFirstCacheObject"));
}
}

Upvotes: 2

Views: 2122

Answers (3)

amate
amate

Reputation: 1

When you run the second JVM check the original coherence cache server node stdout to see if you actually see the new member joining in the cluster (check the MemberSet). You might just be running two separate JVMs which are completely unaware of each other; hence CacheFactory.getCache("myCache") is creating the cache in each JVM.

The way to go around this is to use cache-server.cmd to start a coherence cache server and then run your eclipse program with a distributed/partitioned or replicated scheme. That way, even when your program exits, the actual data would be live in the the coherence cache server for the second JVM to retrieve when it joins the "same cluster".

Upvotes: 0

Vijay Krish
Vijay Krish

Reputation: 297

In the command prompt you have started the server(as stand-alone) and the clients have joined the server. So all the data in the cache will be available until the server stops, even if the client which inserted the data into the cache leaves the server session.
But in the above case, the coherence cache resides in the JVM(Eclipse) itself and not as stand alone server. So you are getting null value when the program exists.

Upvotes: 1

Radim Vansa
Radim Vansa

Reputation: 5888

If the coherence cache resides in the JVM (it is not ran as standalone server), then all the data get discarded after your program finishes (you use in-memory storage). Try to put Thread.sleep(200000); to the end of the first program and then run the second instance within the timeout.

Upvotes: 3

Related Questions