- 论坛徽章:
- 0
|
String s = new String("s")
String s = new String("s")产生几个OBJECT?
我认为是两个一个是STACK中的"s",一个是HEAP中指向"s"的s,因为使用new关键字时,JVM不会查看STACK中是否已经有相关对象"s",而是直接分配新的内存给新的对象"s".
关于这样的对错,我可能还需要查看JVM的相关文档的.
关于编程实现细粒度的事务管理的问题:
例如:
Connection conn = DatabaseFactory.getInstance("MSSQL");
PreparedStatement stmp1 = conn.prepareStatement("insert .............");
PreparedStatement stmp2 = conn.prepareStatement("update .............");
stmt1.execute();
stmt2.execute();
此时要求在stmt2失败时仅ROLLBACK到stmt2,而stmt1仍然commit;
在JDBC3.0中提供了SavePoint这个接口可以实现这种细粒度的事务控制,详细可以参考JDK文档,
try{
Connection conn = DatabaseFactory.getInstance("MSSQL");
PreparedStatement stmp1 = conn.prepareStatement("insert .............");
point1 = connection.setSavepoint("point1");
PreparedStatement stmp2 = conn.prepareStatement("update .............");
stmt1.execute();
stmt2.execute();
if(point != null)conn.rollback(point1);
conn.commit();
}catch(Exception e){
if (point1!= null ){
conn.rollback(point1);
conn.commit();
} else
conn.rollback();
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5142/showart_37383.html |
|