How it works...

The first thing to have a look at the following:

@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)

This is completely redundant! Singleton beans are container-managed by default, so you don't need to specify them.

Singletons are designed for concurrent access, so they are the perfect use case for this recipe.

Now let's check the LockType defined at the class level:

@Lock(LockType.READ)@AccessTimeout(value = 10000)public class UserClassLevelBean {    ...}

When we use the @Lock annotation at the class level, the informed LockType will be used for all class methods.

In this case, LockType.READ means that many clients can access a resource at the same time. It is usual for reading data.

In case of some kind of locking, ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.