frankpuppa commented on issue #2229:
URL: https://github.com/apache/plc4x/issues/2229#issuecomment-3228245741
Hello Chris, thank you for your reply.
Yes I agree, but old connections should eventually be closed and resources
should be releases somehow.
Nevertheless, the code I posted executes this only once:
```
plcConnection = connectionManager.getConnection(plcConnectionString);
```
the rest of the times it simply calls
```
plcConnection.connect()
```
which indeed opens a new connections and it works fine, apart from the
number of threads that keep increasing.
I should have mentioned that I also tried the connection cache but also in
this condition I noticed a strange behavior.
Basically when requesting a plcConnection and the simulator is running,
everything works fine.
```
PlcConnectionManager connectionManager =
CachedPlcConnectionManager.getBuilder().build();
plcConnection = connectionManager.getConnection(plcConnectionString);
```
As soon as I disconnect the simulator, even if I reconnect it, the next
plcConnection which I get from the cache using:
```
plcConnection = connectionManager.getConnection(plcConnectionString);
```
it is not returned as a valid one. It falls into this condition:
```
if (plcConnection == null || !plcConnection.isConnected()) {
logger.info("PLC connection is not alive, exiting...");
return;
}
```
because **plcConnection.isConnected() returns false**. Additionally, calling
connect to a cached connection returns error: Error connecting leased
connection.
To get new alive connections from the connection Manager I have to get a new
instance of the CachedPlcConnectionManager but doing so also increases the
number of live threads. What am I missing here?
Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]