Coherence Hello World
To introduce fundamental concept of oracle coherence application, we will be building simple coherence hello world standalone java application. After running this example you will understand basics of oracle coherence and could move towards integrating in your own application. Please follow steps below:
- Install oracle coherence using this tutorial
- Create maven project name: CoherenceJavaApplication below is final structure of the project:
- Define your cache: Caches should be defined in cache deployment descriptor it should be refer by the name of your application. This makes easy for configuration changes without changing any application code. We will create distributed cache name javahonk-hello-world. To define distributed cache create XML file name: example-config.xml inside src/main/resources directory and copy paste below code:
- Define and configure cluster: Create XML file name tangosol-coherence-override.xml inside src/main/resources directory and copy paste below code:
Note: You can choose any cluster name as you like and address should be chosen between multicast address which ranges from the 18.104.22.168 through 22.214.171.124. You could choose any unique number as your port. Save this file on same location where example-config.xml was saved.
- Now start cache server instance using DefaultCacheServer class also include location of the coherence.jar file as below:
Real command: If you followed tutorial above to install oracle coherence on your local computer then command will be as below:
- Started server screen shot:
- Create standalone java program HelloWorld.java inside com.javahonk package, get cache from CacheFactory, add key value to the cache, retrieve and print its value on the console.
- To run oracle coherence application right click HelloWorld.java –> Run As –> Java Application you will see below Java Honk Hello World! output:
Download sample project: CoherenceJavaApplication