From af5ed77f5986bb9d82f991636829f25af630db13 Mon Sep 17 00:00:00 2001 From: Kohei Tamura Date: Mon, 24 Apr 2017 16:00:45 +0900 Subject: [PATCH] Improve dead lock servlet 2 --- pom.xml | 10 +++++----- .../easybuggy/troubles/DeadlockServlet2.java | 12 +++--------- src/main/resources/log4j.xml | 6 +++--- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index d9a5936d..5e06d4a2 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ mysql mysql-connector-java - 5.1.17 + 5.1.25 org.slf4j @@ -169,15 +169,15 @@ exec-maven-plugin 1.2 - + - + startup-embedded-jetty install diff --git a/src/main/java/org/t246osslab/easybuggy/troubles/DeadlockServlet2.java b/src/main/java/org/t246osslab/easybuggy/troubles/DeadlockServlet2.java index ee4efe39..ab9ee8e3 100644 --- a/src/main/java/org/t246osslab/easybuggy/troubles/DeadlockServlet2.java +++ b/src/main/java/org/t246osslab/easybuggy/troubles/DeadlockServlet2.java @@ -156,11 +156,8 @@ private String updateUsers(ArrayList users, Locale locale) { int executeUpdate = 0; String resultMessage = ""; try { - conn = DBClient.getConnection(); conn.setAutoCommit(false); - // conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); - stmt = conn.prepareStatement("Update users set name = ?, phone = ?, mail = ? where id = ?"); for (User user : users) { stmt.setString(1, user.getName()); @@ -168,6 +165,7 @@ private String updateUsers(ArrayList users, Locale locale) { stmt.setString(3, user.getMail()); stmt.setString(4, user.getUserId()); executeUpdate = executeUpdate + stmt.executeUpdate(); + log.info(user.getUserId() +" is updated."); Thread.sleep(500); } conn.commit(); @@ -179,12 +177,8 @@ private String updateUsers(ArrayList users, Locale locale) { log.error("SQLTransactionRollbackException occurs: ", e); rollbak(conn); } catch (SQLException e) { - if ("41000".equals(e.getSQLState())) { - resultMessage = MessageUtils.getErrMsg("msg.deadlock.occurs", locale); - } else { - resultMessage = MessageUtils.getErrMsg("msg.unknown.exception.occur", new String[] { e.getMessage() }, - locale); - } + resultMessage = MessageUtils.getErrMsg("msg.unknown.exception.occur", new String[] { e.getMessage() }, + locale); log.error("SQLException occurs: ", e); rollbak(conn); } catch (Exception e) { diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index 8ec15add..59b8086b 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -6,7 +6,7 @@ - + @@ -16,12 +16,12 @@ - + - +