Managing Concurrent Requests with EJB Containers

As you probably know, an important solution offered by EJB containers is the ability to manage concurrent requests and satisfy multiple clients while avoiding unpleasant issues. When the number of requests is too large and the available memory is insufficient, EJB containers try to use the hard disk to store the conversational state of each request that can’t be stored in memory. To accomplish this, the EJB container serializes the conversational state and stores it on the hard disk (known as the passivate process), and at the right moment it deserializes (restores) the conversational state and responds to the request (known as the activate process).

The limitation of this approach is that the container can’t serialize complex objects, such as sockets, database connections, JMS connections, and so on, because it can’t “capture” the state of such conversational states. This is why the EJB 3 provides the PrePassivate and PostActivate methods, annotated with @PrePassivate and @PostActivate, respectively. The first one, @PrePassivate, is called before storing the conversational state, which enables the developer to close any sockets and/or connections to databases and so on.

//called before storing conversational [email protected] public void passivate(InvocationContext ic){   //close any socket, database connection etc.}

When the conversational state needs to be restored from hard disk, the @PostActivate method is called after the bean is restored (activated) to allow the developer to restore the potential connections, sockets and so on.

//called after the conversational state is restored (activated)@PostActivatepublic void activate(InvocationContext ic){   //reopen any socket, database connection etc.}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.