JdonFramework 6.6 執行Robot DCI兩次獲得Service不equals的疑問?

owerlen發表於2013-03-18
以下程式碼基於JdonFramewo6.6-->examples-->Robot
1、用於Application方式執行
public class RobotSetup {

public static void main(String[] args) {
AppUtil appUtil = new AppUtil();
Context context = (Context) appUtil.getService("context");
Context context1 = (Context) appUtil.getService("context");
System.out.println(context);
System.out.println(context1);
System.out.println(context.hashCode());
System.out.println(context1.hashCode());
System.out.println(context == context1);
System.out.println(context.hashCode() == context1.hashCode());
System.out.println(context.equals(context1));
appUtil.stop();
}
// output:
// com.test.jdon.demo.robot.service.TestContext@93d6bc
// com.test.jdon.demo.robot.service.TestContext@93d6bc
// 9688764
// 9688764
// false
// true
// false

}

發現兩次拿到的context hashcode相等,但是不==,不equals,誰能幫忙分析一下嗎?

2、用於Web App方式執行
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

String myname = req.getParameter("myname");
System.out.println("doGet active :" + myname);
Context context = (Context) WebAppUtil.getService("context", req);

Context context1 = (Context) WebAppUtil.getService("context", req);
System.out.println(context);
System.out.println(context1);
System.out.println(context.hashCode());
System.out.println(context1.hashCode());
System.out.println(context == context1);
System.out.println(context.hashCode() == context1.hashCode());
System.out.println(context.equals(context1));
Robot robot = new Robot();
robot.setName(myname);
String id = Integer.toString(robot.hashCode());
robot.setId(id);
context.save(robot);

String result = context.hello(id);
resp.getWriter().print("robot response:" + result);
resp.getWriter().print("\n");
result = context.touch(id);
resp.getWriter().print("robot response:" + result);
resp.getWriter().close();
}
// output
// doGet active :jdon
// 2013-03-18 16:15:33,678 [http-8080-1] INFO JdonFramework - is ready.
// 2013-03-18 16:15:34,910 [http-8080-1] INFO JdonFramework - Jdon Framework started successfully!
// init object...
// com.test.jdon.demo.robot.service.TestContext@df33ae
// com.test.jdon.demo.robot.service.TestContext@df33ae
// 14627758
// 14627758
// true
// true
// false
}
發現兩次拿到的context hashcode相等,context==context1,但是不equals,誰能幫忙分析一下嗎?

[該貼被owerlen於2013-03-18 16:30修改過]

相關文章