Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the problem with the code (EJBHome factory )  RSS feed

Rupesh Raut
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written following code for one time look up of home interface ,
it returns remote interface object(static).
My question is is there any performance issue with the code or
somthing wrong with this code ?

import java.util.* ;
import javax.naming.*;
import ejb.sysconfig.*;
public class EjbFactory {
private static SysConfigRemote sysConfigRemote=null;
private EjbFactory(){}
* @description creating SysConfig ejb obect
* @return void
public static void createSysConfigRemote() {
InitialContext ctx = new InitialContext();
SysConfigHome home = (SysConfigHome)ctx.lookup("sysconfig/SysConfig");
sysConfigRemote = home.create();
System.out.println("SysConfig EJB Created");
}catch(Exception excp)
}// end of createSysConfigRemote()

* @description
* @return SysConfigRemote
public static SysConfigRemote getSysConfigRemote(){
return sysConfigRemote;
}// end of getSysConfigRemote
}//end of class
[ November 29, 2003: Message edited by: rupeshraut ]
Bill Pugh
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see 4 possible problems.
If you get an error in createSysConfigRemote(), sysConfigRemote is still null and getSysConfigRemote will return null.
If SysConfigHome is a remote interface, you should be doing a PortableRemoteObject.narrow rather than a plain downcast.
Since you are using static variables, this probably isn't in an EJB container. So you need to worry about whether or not there might be simultaneous unsynchronized calls to getSysConfigRemote.
createSysConfigRemote() should probably be private.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!