JCache (JSR-107) vs Singleton EJB

640 views Asked by At

I've been using Singleton-EJBs in this fashion (as shown by Adam Bien in his blog):

@Singleton
public class MyCache {

    ConcurrentHashMap<String, Object> myMap= new ConcurrentHashMap<String, Object<>();

    //...Crud methods to the map
}

Now with JCache being a candidate for java-ee-8 i read the following in the JCache spec:

A Cache is a Map-like data-structure that permits the temporary storage of Key-based Values. A Cache is owned by a single CacheManager.

Assuming JCache makes it into the next java-ee spec, should something else be prefered over above?

What additional features will JCache API enable?

2

There are 2 answers

0
Miko Matsumura On

JCache will be very interesting now that it has been submitted as final in Java EE 8, and is getting more widespread vendor support.

In particular, one of the things enabled that is intriguing is the support for Entry Processor which is a way of talking to distributed data that maximizes in-memory performance with a minimum of locking and concurrency issues by using distributed processing across your cluster.

JCache looks like a fundamentally new way of looking at plain old caching, which migrates the whole conversation towards fully distributed caches that leverage both RAM and CPU across the cluster. This takes care of distributed computing in a more cloud-friendly (read: elastically scalable) way than local caching and in a way that leverages distributed processing in addition to distributed RAM.

0
Arjan Tijms On

Now with JCache being a candidate for java-ee-8

There's indeed a very high chance that JCache will be in Java EE 8, but don't forget you can already use the reference implementation in Java EE 7 and even Java EE 6.

What additional features will JCache API enable?

A particularly nice and modern feature of JCache are the caching annotations for CDI beans. Besides being plain handy, they may also be able to help for those situations where JSF consults getter and other methods a tad too often.

I've collected a number of JCache related articles here. Especially the 2011 in-depth explanation by spec lead Greg Luck is a great read.