Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/jTPCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ else if(newOrderWeightValue == 0 && paymentWeightValue == 0 && orderStatusWeight
conn, dbType,
transactionsPerTerminal, terminalWarehouseFixed,
paymentWeightValue, orderStatusWeightValue,
deliveryWeightValue, stockLevelWeightValue, numWarehouses, limPerMin_Terminal, this);
deliveryWeightValue, stockLevelWeightValue, numWarehouses, limPerMin_Terminal, this, database, dbProps);

terminals[i] = terminal;
terminalNames[i] = terminalName;
Expand Down
2 changes: 1 addition & 1 deletion src/client/jTPCCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,6 @@ public void commit()
public void rollback()
throws SQLException
{
dbConn.rollback();
dbConn.rollback();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式调一下

}
}
33 changes: 32 additions & 1 deletion src/client/jTPCCTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.sql.*;
import java.sql.Date;
import java.util.*;
import javax.naming.CommunicationException;
import javax.swing.*;


Expand Down Expand Up @@ -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;
Expand All @@ -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("");
Expand Down Expand Up @@ -165,6 +173,13 @@ private void executeTransactions(int numTransactions)
{
continue;
}
catch (SQLException | CommunicationException e ){
try {
retryConnect();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有保护全下面还有类似场景

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断一下错误原因,如果是关闭再重连

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 这样处理是不是更好点

} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
catch (Exception e)
{
log.fatal(e.getMessage());
Expand Down Expand Up @@ -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);
}




}