Skip to content

Commit

Permalink
fix(plc4j/connection-cache): Fixed an issue with the timeout handler …
Browse files Browse the repository at this point in the history
…not being cancelled
  • Loading branch information
chrisdutz committed Mar 26, 2023
1 parent ff37b11 commit bf4f1e2
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public class LeasedPlcConnection implements PlcConnection {
private final ConnectionContainer connectionContainer;
private PlcConnection connection;
private boolean invalidateConnection;
private Timer usageTimer;

public LeasedPlcConnection(ConnectionContainer connectionContainer, PlcConnection connection, Duration maxUseTime) {
this.connectionContainer = connectionContainer;
this.connection = connection;
this.invalidateConnection = false;
Timer usageTimer = new Timer();
usageTimer.schedule(new TimerTask() {
this.usageTimer = new Timer();
this.usageTimer.schedule(new TimerTask() {
@Override
public void run() {
close();
Expand All @@ -57,6 +58,9 @@ public void run() {

@Override
public synchronized void close() {
// Cancel automatically timing out.
usageTimer.cancel();

// Make the connection unusable.
connection = null;

Expand Down

0 comments on commit bf4f1e2

Please sign in to comment.