电脑慢的解决方法<二>
2007-12-22 22:24
211 查看
同时有两个线程同时访问这个servlet会导致一些问题:
第一个线程等待第二个的notify
而因为事物级别的提升导致第二个线程等待第一个线程的结束。
最终导致:死锁
第一个线程等待第二个的notify
而因为事物级别的提升导致第二个线程等待第一个线程的结束。
最终导致:死锁
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Class.forName("com.mysql.jdbc.Driver"); Connection c = DriverManager.getConnection("jdbc:mysql://localhost/hibernate", "root", "19841230"); c.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); c.setAutoCommit(false); Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery("select student.STUDENT_NAME " + "from student where student.STUDENT_NAME='FrenchMan' "); if(!rs.next()){ synchronized(lock){ if(i++%2==0){ lock.wait(); } else { lock.notify(); } stmt.execute("insert into student(student_name) values('FrenchMan')"); } } c.commit(); rs.close(); stmt.close(); c.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
相关文章推荐
- 电脑慢的解决方法<一>
- <img src="中文文件名" /> 无法显示图片,图片名改成英文就可以显示;试了下在电脑桌面写了个HTML测试下,可以显示中文名称的图片,解决方法
- C# 项目迁移 Microsoft.VisualStudio.Tools.Office.BuildTasks 生成解决方法报错:请确认 <UsingTask> 声明正确,该程序集及其所有依赖项都可用
- <UNIX环境高级编程> 第三版 apue.h 配置问题解决方法
- File "/Volumes/android/.repo/repo/main.py", line 531, in <module> _Main(sys.argv[1:]) 解决方法
- web.xml is missing and <failOnMissingWebXml> is set to true解决方法
- 如何解决GitHub冲突<二>:使用命令行解决合并冲突
- [转载]CSS<a href>链接样式冲突解决方法!
- 解决webApi<Message>An error has occurred.</Message>不能写多个Get方法的问题
- 数据库死锁问题 及 解决方法 <收藏>
- 数据库死锁问题 及 解决方法 <收藏>
- 解决 ”不允许在查询中显式构造实体类型“问题及使用其他方法实现返回 List<Model对象>或者IQueryable<Model对象>对象
- Android SDK Manager更新<dl-ssl.google.com> != <www.google.com> 问题解决方法
- IE7下在DD DT中插入<a>元素导致样式跑偏的解决方法
- 一些编译错误及解决方法<记录>
- VC6.0编程用到#include <unistd.h>编译时出现的错误及解决方法
- flex 无法将“<mx:>”解析为组件执行.解决方法
- Windows2003建立FTP服务器以及报530 User <用户名> cannot log in home directory inaccessible的解决方法
- android.view.InflateException: Binary XML file line #29: Error inflating class <unknown> 解决方法
- QT编译错误 No such file or directory #include<QApplication>解决方法