-
Notifications
You must be signed in to change notification settings - Fork 80
automatic reconnect with retry after connection closed #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0-mysql-support-opt-2.1
Are you sure you want to change the base?
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,6 +316,6 @@ public void commit() | |
| public void rollback() | ||
| throws SQLException | ||
| { | ||
| dbConn.rollback(); | ||
| dbConn.rollback(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import java.sql.*; | ||
| import java.sql.Date; | ||
| import java.util.*; | ||
| import javax.naming.CommunicationException; | ||
| import javax.swing.*; | ||
|
|
||
|
|
||
|
|
@@ -45,12 +46,16 @@ public class jTPCCTerminal implements jTPCCConfig, Runnable | |
| jTPCCConnection db = null; | ||
| int dbType = 0; | ||
|
|
||
| private String database = ""; | ||
| private Properties dbProps = null; | ||
|
|
||
| public jTPCCTerminal | ||
| (String terminalName, int terminalWarehouseID, int terminalDistrictID, | ||
| Connection conn, int dbType, | ||
| int numTransactions, boolean terminalWarehouseFixed, | ||
| int paymentWeight, int orderStatusWeight, | ||
| int deliveryWeight, int stockLevelWeight, int numWarehouses, int limPerMin_Terminal, jTPCC parent) throws SQLException | ||
| int deliveryWeight, int stockLevelWeight, int numWarehouses, int limPerMin_Terminal, jTPCC parent, | ||
| String database, Properties dbProp) throws SQLException | ||
| { | ||
| this.terminalName = terminalName; | ||
| this.conn = conn; | ||
|
|
@@ -76,6 +81,9 @@ public class jTPCCTerminal implements jTPCCConfig, Runnable | |
| this.newOrderCounter = 0; | ||
| this.limPerMin_Terminal = limPerMin_Terminal; | ||
|
|
||
| this.database = database; | ||
| this.dbProps = dbProp; | ||
|
|
||
| this.db = new jTPCCConnection(conn, dbType); | ||
|
|
||
| terminalMessage(""); | ||
|
|
@@ -165,6 +173,13 @@ private void executeTransactions(int numTransactions) | |
| { | ||
| continue; | ||
| } | ||
| catch (SQLException | CommunicationException e ){ | ||
| try { | ||
| retryConnect(); | ||
|
||
| } catch (SQLException ex) { | ||
| throw new RuntimeException(ex); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| log.fatal(e.getMessage()); | ||
|
|
@@ -367,5 +382,21 @@ void transCommit() { | |
| } // end transCommit() | ||
|
|
||
|
|
||
| void retryConnect() throws SQLException { | ||
| Connection c = DriverManager.getConnection(this.database, this.dbProps); | ||
| c.setAutoCommit(false); | ||
| this.conn = c; | ||
| this.stmt = c.createStatement(); | ||
| this.stmt.setMaxRows(200); | ||
| this.stmt.setFetchSize(100); | ||
|
|
||
| this.stmt1 = c.createStatement(); | ||
| this.stmt1.setMaxRows(1); | ||
|
|
||
| this.db = new jTPCCConnection(c, dbType); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式调一下