public class UserBeanTestClient extends Object {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private UserHome userHome = null;
private User user = null; //Construct the EJB test client
public UserBeanTestClient() {
initialize();
} public void initialize() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
} try {
//get naming context
Context context = new InitialContext(); //look up jndi name
Object ref = context.lookup("UserBean");
//look up jndi name and cast to Home interface
userHome = (UserHome) PortableRemoteObject.narrow(ref, UserHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access through Home interface.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed initializing bean access.");
}
e.printStackTrace();
}
} //----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//---------------------------------------------------------------------------- public User create() {
long startTime = 0;
if (logging) {
log("Calling create()");
startTime = System.currentTimeMillis();
}
try {
user = userHome.create();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: create()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: create()");
}
e.printStackTrace();
} if (logging) {
log("Return value from create(): " + user + ".");
}
return user;
} //----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//---------------------------------------------------------------------------- public UserHomeBean getUserHomeBean() {
UserHomeBean returnValue = null; if (user == null) {
System.out.println("Error in getUserHomeBean(): " + ERROR_NULL_REMOTE);
return returnValue;
} long startTime = 0;
if (logging) {
log("Calling getUserHomeBean()");
startTime = System.currentTimeMillis();
} try {
returnValue = user.getUserHomeBean();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getUserHomeBean()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getUserHomeBean()");
}
e.printStackTrace();
} if (logging) {
log("Return value from getUserHomeBean(): " + returnValue + ".");
}
return returnValue;
} //----------------------------------------------------------------------------
// Utility Methods
//---------------------------------------------------------------------------- private void log(String message) {
if (message == null) {
System.out.println("-- null");
return ;
}
if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
}
else {
System.out.println("-- " + message);
}
}
//Main method public static void main(String[] args) {
UserBeanTestClient client = new UserBeanTestClient();
client.create();
try{
System.out.println(client.getUserHomeBean().getMessageSum());
client.log("############################################");
client.user.remove();
}catch(Exception e){ }
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}
看看这个模仿写就可以知道多少时间
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private UserHome userHome = null;
private User user = null; //Construct the EJB test client
public UserBeanTestClient() {
initialize();
} public void initialize() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
} try {
//get naming context
Context context = new InitialContext(); //look up jndi name
Object ref = context.lookup("UserBean");
//look up jndi name and cast to Home interface
userHome = (UserHome) PortableRemoteObject.narrow(ref, UserHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access through Home interface.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed initializing bean access.");
}
e.printStackTrace();
}
} //----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//---------------------------------------------------------------------------- public User create() {
long startTime = 0;
if (logging) {
log("Calling create()");
startTime = System.currentTimeMillis();
}
try {
user = userHome.create();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: create()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: create()");
}
e.printStackTrace();
} if (logging) {
log("Return value from create(): " + user + ".");
}
return user;
} //----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//---------------------------------------------------------------------------- public UserHomeBean getUserHomeBean() {
UserHomeBean returnValue = null; if (user == null) {
System.out.println("Error in getUserHomeBean(): " + ERROR_NULL_REMOTE);
return returnValue;
} long startTime = 0;
if (logging) {
log("Calling getUserHomeBean()");
startTime = System.currentTimeMillis();
} try {
returnValue = user.getUserHomeBean();
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded: getUserHomeBean()");
log("Execution time: " + (endTime - startTime) + " ms.");
}
}
catch(Exception e) {
if (logging) {
log("Failed: getUserHomeBean()");
}
e.printStackTrace();
} if (logging) {
log("Return value from getUserHomeBean(): " + returnValue + ".");
}
return returnValue;
} //----------------------------------------------------------------------------
// Utility Methods
//---------------------------------------------------------------------------- private void log(String message) {
if (message == null) {
System.out.println("-- null");
return ;
}
if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
}
else {
System.out.println("-- " + message);
}
}
//Main method public static void main(String[] args) {
UserBeanTestClient client = new UserBeanTestClient();
client.create();
try{
System.out.println(client.getUserHomeBean().getMessageSum());
client.log("############################################");
client.user.remove();
}catch(Exception e){ }
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}
看看这个模仿写就可以知道多少时间
我机子的配置是:
CPU:2G
内存:512M
WEBLOGIC
表里有100个字段,速度为1秒大概75条记录。不知道你们的会是多少,不如大家说出来做个比较.