I have deployed applications like below in the domain mode
MyWebApp.war ---> which has web tier
MyEjb.jar --> which has all ejbs
service.jar --> from where ejb is invoked
Both are deployed in the domain mode.
and while invoking the same I use
java:global/MyEjb/...
This works but I want to know the performance impact as it is deployed on the same server. And also what needs to be changed if I want to access it as local.
As If I access it with java:app/MyEjb/..
It is not able to find the bean.
And also, If i am invoking the ejb from same server and using below code
Hashtable Props = new Hashtable();
Props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
Props.put(Context.PROVIDER_URL, "remote://localhost:4447");
Props.put("jboss.naming.client.ejb.context", Boolean.valueOf(true));
Why to use "remote" in this case? Is there any other way to call locally?
My objective is to invoke the ejb locally since everything is running on the same JVM.
You are doing a JNDI lookup for local and remote access. The string you are passing to the Context
defines whether this is a remote ore local lookup (together with the properties passed to the Context
).
For a remote lookup your name will start with ejb:...
(as explained for example here). Additionally you are creating an instance of Context
by passing properties like "org.jboss.ejb.client.naming"
which denotes the Java package in which the context factory resides:
Properties contextProperties = new Properties();
contextPropertiesL.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(contextProperties);
If your name starts with java:...
then it is looked up locally. Locally means within the same JVM and therefore no serialization/deserialization of the objects has to be done. Local stubs are therefore more efficient in terms of runtime as the invocation of an EJB is just like the invocation of any other object's methods in your JVM.
The properties you are passing to the Context
are only necessary in case you want to do a remote lookup.