how to implement a cache in ejb 3.0?

Viewed 4692

I have a customer who's stuck in an EJB 3.0 environment. No @Singleton, no bean-managed concurrency :-(

Considering thread management and synchronization is forbidden by the ejb specification, how to implement a cache? In essence, I want an non-synchronized object cache for some costly operations.

5 Answers

And I use Redis with Jedis for temporary values in memory.

See the link below

https://redislabs.com/lp/redis-java/

Redis comes with installers for multiple operating systems.

Example:

import redis.clients.jedis.Jedis; 

public class RedisStringJava { 
   public static void main(String[] args) { 
      //Connecting to Redis server on localhost 
      Jedis jedis = new Jedis("localhost"); 
      System.out.println("Connected"); 
      //set the data in redis string and expire in default time
      jedis.set("param_name", "Param value"); 
      // Get the stored data and print it 
      System.out.println("Stored string in redis:: "+ jedis.get("param_name")); 
   } 
}
Related