Professional Documents
Culture Documents
Optimistic Concurrency
An optimistic approach assumes conflicts won’t occur, and deal with them when they do occur.
EJB (also non-EJB) implements a strategy to detect whether a change has occurred. Locks are
placed on the database only for a small portion of the time.
Suitable for long transactions.
Suitable for systems requiring frequent concurrent accesses.
The optimistic locking is used in the context of cursors. The optimistic locking works as follows:
No locks are acquired as rows are read.
No locks are acquired while values in the current row are changed.
When changes are saved, a copy of the row in the database is read in the locked mode.
If the data was changed after it was read into the cursor, an error is raised so that the
transaction can be rolled back and retried.
17. How can we determine if the data is stale (for example when using optimistic locking)?
We can use the following strategy to determine if the data is stale:
Adding version numbers
Add a version number (Integer) to the underlying table.
Carry the version number along with any data read into memory (through value
object, entity bean etc).
Before performing any update compare the current version number with the
database version number.
If the version numbers are equal update the data and increment the version
number.
If the value object or entity bean is carrying an older version number, reject the
update and throw an exception.
Adding a timestamp to the underlying database table.
Comparing the data values.
18. EJB invocation is based upon which design pattern? What is Service locator design pattern?
19. How do you call Enterprise Java beans from Servlet or JSP?
20. Does EJB 3.0 support dependency Injection?
21. What are the rules must follow for Session Bean?
It implements the SessionBean interface.
The class is defined as public.
The class cannot be defined as abstract or final.
It implements the business methods.
It contains a public constructor with no parameters.
It must not define the finalize method.
22. How can i maintain a user session between servlets and stateful session ejbs?
23. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a
value in the HttpSession from inside an EJB?
24. What is EJB client JAR file?
An EJB client JAR file is an optional JAR file that can contain all the class files that a client
program needs to use the client view of the enterprise beans that are contained in the EJB JAR
file. If you decide not to create a client JAR file for an EJB module, all of the client interface
classes will be in the EJB JAR file.
25. What is the difference between JMS and RPC?
RPC uses synchronous messaging while JMS uses asynchronous messaging approach.
In RPC the method invoker waits for the method to finish execution and return the control back
to the invoker.
In JMS the message sender just sends the message to the destination and continues it's own
processing.
26. What is Remote Procedure Calls, RPC?
In distributed systems, a client calls a procedure stored on a server. This is called calling a
remote procedure stored on a server. Though, the call is made as if the procedure was stored on
the local machine.
The steps in which a RPC is made are:
The client calls the procedure
The client stub builds the message.
The message is sent over the network.
The Server OS gives the message to the server stub.
The server stub unpacks the message.
The stub makes a local call to the procedure.
The server does the work and returns the result to the server stub.
The stub packs the message and traps to the kernel.
The remote kernel sends the message the client kernel.
The client kernel gives the message to the client stub.
The client stub unpacks the result and gives to the client.
27. Explain how RMI clients contact remote RMI servers?
The client procedure calls the client stub in the normal way.
The client stub builds a message and traps to the kernel.
The kernel sends the message to the remote kernel.
The remote kernel gives the message to the server stub
The server stub unpacks the parameters and calls the server.
The server does the work and returns the result to the stub.
The server stub packs it in a message and traps to the kernel.
The remote kernel sends the message to the clients kernel.
The clients’ kernel gives the message to the client stub.
The stub unpacks the result and returns to the client.