Skip to content

Commit

Permalink
Improve dead lock servlet 2
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Apr 24, 2017
1 parent df4e228 commit af5ed77
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -169,15 +169,15 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<!-- Comment out Payara sections to avoid proxy error due to slow downloading. -->
<!-- <dependencies>
<dependencies>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-micro</artifactId>
<version>4.1.1.162</version>
</dependency>
</dependencies> -->
</dependencies>
<executions>
<!-- <execution>
<execution>
<id>payara-uber-jar</id>
<phase>package</phase>
<goals>
Expand All @@ -201,7 +201,7 @@
<artifactId>payara-micro</artifactId>
</executableDependency>
</configuration>
</execution> -->
</execution>
<execution>
<id>startup-embedded-jetty</id>
<phase>install</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,16 @@ private String updateUsers(ArrayList<User> 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());
stmt.setString(2, user.getPhone());
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();
Expand All @@ -179,12 +177,8 @@ private String updateUsers(ArrayList<User> 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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %5p %c{1} %m%n" />
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %5p %t %c{1} %m%n" />
</layout>
</appender>

Expand All @@ -16,12 +16,12 @@
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %5p %c{1} %m%n" />
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %5p %t %c{1} %m%n" />
</layout>
</appender>

<root>
<priority value ="ERROR" />
<priority value ="INFO" />
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
Expand Down

0 comments on commit af5ed77

Please sign in to comment.