Search code examples
javajakarta-eermiejb-2.xiiop

Concept of stub and Skeleton in EJB 2.X


As per my knowledge, in the EJB 2.x, the client uses the home interface to ask for a reference to the component interface and calls Enterprise java bean’s business method using that reference. But the concept of stub and skeleton are not clear to me.

Is the reference to the component interface acts as a stub? Then which one act as a skeleton?

Please clarify.


Solution

  • Stub and skeleton are actually RMI concepts, EJB is just reusing them. As such, they are only needed when you are using remote interfaces.

    • Stub is used by the client to invoke methods on the remote EJB -- it is basically a proxy object that implements the remote interface. It is responsible for serializing the invocation into a byte stream and sending it to the server hosting the EJB.
    • Skeleton is running on the server side -- it receives the remote calls from the stub over the network, deserializes the invocation and and delegates it to the EJB.

    See also: Java RMI : What is the role of the stub-skeleton that are generated by the rmic compiler

    Nowadays, stubs and skeletons are typically generated at runtime (or the same function is just handled via reflection), so you do not need to worry about them (see also Do I need RMI stubs to access EJBs from my java client? - this is specific to Glassfish, but the general principles usually apply also to other containers).