|
|
|
@ -31,7 +31,9 @@ import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
|
import java.security.AccessControlException;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
@ -858,7 +860,7 @@ public class HikariConfig implements HikariConfigMXBean
|
|
|
|
|
public void validate()
|
|
|
|
|
{
|
|
|
|
|
if (poolName == null) {
|
|
|
|
|
poolName = "HikariPool-" + generatePoolNumber();
|
|
|
|
|
poolName = generatePoolName();
|
|
|
|
|
}
|
|
|
|
|
else if (isRegisterMbeans && poolName.contains(":")) {
|
|
|
|
|
throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX");
|
|
|
|
@ -1014,13 +1016,29 @@ public class HikariConfig implements HikariConfigMXBean
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int generatePoolNumber()
|
|
|
|
|
private String generatePoolName()
|
|
|
|
|
{
|
|
|
|
|
// Pool number is global to the VM to avoid overlapping pool numbers in classloader scoped environments
|
|
|
|
|
synchronized (System.getProperties()) {
|
|
|
|
|
final int next = Integer.getInteger("com.zaxxer.hikari.pool_number", 0) + 1;
|
|
|
|
|
System.setProperty("com.zaxxer.hikari.pool_number", String.valueOf(next));
|
|
|
|
|
return next;
|
|
|
|
|
final String prefix = "HikariPool-";
|
|
|
|
|
try {
|
|
|
|
|
// Pool number is global to the VM to avoid overlapping pool numbers in classloader scoped environments
|
|
|
|
|
synchronized (System.getProperties()) {
|
|
|
|
|
final String next = String.valueOf(Integer.getInteger("com.zaxxer.hikari.pool_number", 0) + 1);
|
|
|
|
|
System.setProperty("com.zaxxer.hikari.pool_number", next);
|
|
|
|
|
return prefix + next;
|
|
|
|
|
}
|
|
|
|
|
} catch (AccessControlException e) {
|
|
|
|
|
// The SecurityManager didn't allow us to read/write system properties
|
|
|
|
|
// so just generate a random pool number instead
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
StringBuilder buf = new StringBuilder(prefix);
|
|
|
|
|
|
|
|
|
|
while (buf.length() < prefix.length() + 4) {
|
|
|
|
|
buf.append(Long.toString(Math.abs(random.nextLong()), Character.MAX_RADIX));
|
|
|
|
|
}
|
|
|
|
|
String name = buf.toString().substring(0, prefix.length() + 4);
|
|
|
|
|
LOGGER.info("{} - assigned random pool name (security manager prevented access to system properties)", name);
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|