fix connection close issue
This commit is contained in:
parent
883365227b
commit
04d5338294
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
mqtt.broker = tcp://172.16.2.15:1883
|
;mqtt.broker = tcp://172.16.2.15:1883
|
||||||
;mqtt.broker = tcp://eupenstrasse20.dynamic.hottis.de:2883
|
mqtt.broker = tcp://eupenstrasse20.dynamic.hottis.de:2883
|
||||||
;mqtt.username = tron
|
mqtt.username = tron
|
||||||
;mqtt.password = geheim123
|
mqtt.password = geheim123
|
||||||
|
|
||||||
mbus.dataparser.1 = light,Light,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
mbus.dataparser.1 = light,Light,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
||||||
mbus.dataparser.2 = computer,Computer,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
mbus.dataparser.2 = computer,Computer,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
||||||
@ -14,4 +14,5 @@ mbus.dataparser.8 = thermom.,null,de.hottis.measurementCollector.HottisFourChann
|
|||||||
|
|
||||||
jms.broker = tcp://localhost:61616
|
jms.broker = tcp://localhost:61616
|
||||||
jms.clientid = mcol
|
jms.clientid = mcol
|
||||||
jms.parseddata.topic = IoT/Measurement
|
jms.parseddata.topic = IoT/Measurement
|
||||||
|
|
||||||
|
@ -124,6 +124,8 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
|||||||
try {
|
try {
|
||||||
int itemCnt = 0;
|
int itemCnt = 0;
|
||||||
|
|
||||||
|
dbCon = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
|
||||||
|
logger.debug("New connection opened: " + dbCon);
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
ADataObject ado = queue.dequeue();
|
ADataObject ado = queue.dequeue();
|
||||||
@ -131,15 +133,16 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
|||||||
logger.warn("DatabaseEngine found no data");
|
logger.warn("DatabaseEngine found no data");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dbCon = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
|
|
||||||
|
|
||||||
String key = ado.getClass().getName();
|
String key = ado.getClass().getName();
|
||||||
PreparedStatement pstmt;
|
PreparedStatement pstmt;
|
||||||
if (! preparedStatements.containsKey(key)) {
|
if (! preparedStatements.containsKey(key)) {
|
||||||
pstmt = dbCon.prepareStatement(createStatementFromDataObject(ado));
|
pstmt = dbCon.prepareStatement(createStatementFromDataObject(ado));
|
||||||
preparedStatements.put(key, pstmt);
|
preparedStatements.put(key, pstmt);
|
||||||
|
logger.debug("PreparedStatement created for " + key + ": " + pstmt);
|
||||||
} else {
|
} else {
|
||||||
pstmt = preparedStatements.get(key);
|
pstmt = preparedStatements.get(key);
|
||||||
|
logger.debug("PreparedStatement reused for " + key + ": " + pstmt);
|
||||||
}
|
}
|
||||||
bindValue(pstmt, 1, ado.getName());
|
bindValue(pstmt, 1, ado.getName());
|
||||||
bindValue(pstmt, 2, ado.getTimestamp());
|
bindValue(pstmt, 2, ado.getTimestamp());
|
||||||
@ -163,6 +166,7 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
|||||||
} finally {
|
} finally {
|
||||||
for (PreparedStatement p : preparedStatements.values()) {
|
for (PreparedStatement p : preparedStatements.values()) {
|
||||||
try {
|
try {
|
||||||
|
logger.debug("PreparedStatement " + p + " about to close");
|
||||||
p.close();
|
p.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.warn("SQLException when closing prepared statement, nothing will be done");
|
logger.warn("SQLException when closing prepared statement, nothing will be done");
|
||||||
@ -171,6 +175,7 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
|||||||
preparedStatements.clear();
|
preparedStatements.clear();
|
||||||
if (dbCon != null) {
|
if (dbCon != null) {
|
||||||
try {
|
try {
|
||||||
|
logger.debug("Connection " + dbCon + " about to close");
|
||||||
dbCon.close();
|
dbCon.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.warn("SQLException when closing connection, nothing will be done");
|
logger.warn("SQLException when closing connection, nothing will be done");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user