So, as described - this 100% sounds like a bug. If you're not already in contact with support, that should definitely be your next step. There are various short-term workarounds you can try (such as idle connection eviction) that may "fix" the problem, but understanding the core issue is what we're really after. Unfortunately, as previously mentioned, a lot of this JDBC stuff is not really "our" code, as much as just use using off-the-shelf components; specifically, Apache Commons DBCP(2, in 8.0+) for the connection pooling, and whatever JDBC driver for the actual connection.
I know for a fact that there's an internal ticket to investigate connections not being closed on certain databases - that's with our bug analysis team right now, awaiting replication. That may have the same root cause as what you're describing...or it may not.
More specifically,
No, you can't write arbitrary java there. What you do is set various properties and values - extra connection properties could be something like: zeroDateTimeBehavior=CONVERT_TO_NULL;connectTimeout=120000;socketTimeout=120000;useSSL=false;allowPublicKeyRetrieval=truedisableMariaDbDriver
Except, obviously, Oracle's JDBC driver will support a different set of properties than, in this case, MariaDB. The link I posted earlier in the thread is Oracle's API reference on what properties are able to be parsed from a connection string - I have no idea what allowed, expected, or default values for those properties are - only that those are the properties I would expect to do something to the JDBC driver. There may be a more specific manual for Oracle's JDBC driver somewhere - but I couldn't find it.