[
https://issues.apache.org/jira/browse/POOL-393?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Shichao Yuan updated POOL-393:
------------------------------
Description:
When creating may pools, I find that it tasks too much time to register jmx.
In the code, the ObjectName's postfix always starts with 1, so many
InstanceAlreadyExistsExceptions may be thrown before registered successfully.
Maybe a random number is a better choice, or a atomic long.
{quote}
private ObjectName jmxRegister(BaseObjectPoolConfig config,
String jmxNameBase, String jmxNamePrefix) {
ObjectName objectName = null;
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
int i = 1;
boolean registered = false;
String base = config.getJmxNameBase();
if (base == null) {
base = jmxNameBase;
}
while (!registered) {
try {
ObjectName objName;
// Skip the numeric suffix for the first pool in case there is
// only one so the names are cleaner.
if (i == 1) {
objName = new ObjectName(base + jmxNamePrefix);
} else {
objName = new ObjectName(base + jmxNamePrefix + i);
}
mbs.registerMBean(this, objName);
objectName = objName;
registered = true;
} catch (MalformedObjectNameException e) {
if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(
jmxNamePrefix) && jmxNameBase.equals(base)) {
// Shouldn't happen. Skip registration if it does.
registered = true;
} else {
// Must be an invalid name. Use the defaults instead.
jmxNamePrefix =
BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
base = jmxNameBase;
}
} catch (InstanceAlreadyExistsException e) {
// Increment the index and try again
i++;
} catch (MBeanRegistrationException e) {
// Shouldn't happen. Skip registration if it does.
registered = true;
} catch (NotCompliantMBeanException e) {
// Shouldn't happen. Skip registration if it does.
registered = true;
}
}
return objectName;
}
{quote}
was:
When creating may pools, I find that it tasks too much time to register jmx.
In the code, the ObjectName's postfix always starts with 1, so many
InstanceAlreadyExistsExceptions may be thrown before registered successfully.
Maybe a random number is a better choice, or a atomic long.
{color:#cc7832}private {color}ObjectName
{color:#ffc66d}jmxRegister{color}(BaseObjectPoolConfig
config{color:#cc7832},{color} String jmxNameBase{color:#cc7832}, {color}String
jmxNamePrefix) {
ObjectName objectName = {color:#cc7832}null;{color} MBeanServer mbs =
ManagementFactory.getPlatformMBeanServer(){color:#cc7832};{color}{color:#cc7832}
int {color}i = {color:#6897bb}1{color}{color:#cc7832};{color}{color:#cc7832}
boolean {color}registered = {color:#cc7832}false;{color} String base =
config.getJmxNameBase(){color:#cc7832};{color}{color:#cc7832} if {color}(base
== {color:#cc7832}null{color}) {
base = jmxNameBase{color:#cc7832};{color} }
{color:#cc7832}while {color}(!registered) {
{color:#cc7832}try {color}{
ObjectName objName{color:#cc7832};{color} {color:#808080}// Skip the numeric
suffix for the first pool in case there is{color}{color:#808080} // only one so
the names are cleaner.{color} {color:#cc7832}if {color}(i ==
{color:#6897bb}1{color}) {
objName = {color:#cc7832}new {color}ObjectName(base +
jmxNamePrefix){color:#cc7832};{color} } {color:#cc7832}else {color}{
objName = {color:#cc7832}new {color}ObjectName(base + jmxNamePrefix +
i){color:#cc7832};{color} }
mbs.registerMBean({color:#cc7832}this, {color}objName){color:#cc7832};{color}
objectName = objName{color:#cc7832};{color} registered =
{color:#cc7832}true;{color} } {color:#cc7832}catch
{color}(MalformedObjectNameException e) {
{color:#cc7832}if
{color}(BaseObjectPoolConfig.{color:#9876aa}DEFAULT_JMX_NAME_PREFIX{color}.equals(
jmxNamePrefix) && jmxNameBase.equals(base)) {
{color:#808080}// Shouldn't happen. Skip registration if it does.{color}
registered = {color:#cc7832}true;{color} } {color:#cc7832}else {color}{
{color:#808080}// Must be an invalid name. Use the defaults instead.{color}
jmxNamePrefix =
BaseObjectPoolConfig.{color:#9876aa}DEFAULT_JMX_NAME_PREFIX{color}{color:#cc7832};{color}
base = jmxNameBase{color:#cc7832};{color} }
} {color:#cc7832}catch {color}(InstanceAlreadyExistsException e) {
{color:#808080}// Increment the index and try again{color}
i++{color:#cc7832};{color} } {color:#cc7832}catch
{color}(MBeanRegistrationException e) {
{color:#808080}// Shouldn't happen. Skip registration if it does.{color}
registered = {color:#cc7832}true;{color} } {color:#cc7832}catch
{color}(NotCompliantMBeanException e) {
{color:#808080}// Shouldn't happen. Skip registration if it does.{color}
registered = {color:#cc7832}true;{color} }
}
{color:#cc7832}return {color}objectName{color:#cc7832};{color}}
> BaseGenericObjectPool.jmxRegister may cost too much time
> --------------------------------------------------------
>
> Key: POOL-393
> URL: https://issues.apache.org/jira/browse/POOL-393
> Project: Commons Pool
> Issue Type: Improvement
> Affects Versions: 2.4.2
> Reporter: Shichao Yuan
> Priority: Major
>
>
> When creating may pools, I find that it tasks too much time to register jmx.
> In the code, the ObjectName's postfix always starts with 1, so many
> InstanceAlreadyExistsExceptions may be thrown before registered successfully.
> Maybe a random number is a better choice, or a atomic long.
> {quote}
> private ObjectName jmxRegister(BaseObjectPoolConfig config,
> String jmxNameBase, String jmxNamePrefix) {
> ObjectName objectName = null;
> MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
> int i = 1;
> boolean registered = false;
> String base = config.getJmxNameBase();
> if (base == null) {
> base = jmxNameBase;
> }
> while (!registered) {
> try {
> ObjectName objName;
> // Skip the numeric suffix for the first pool in case there is
> // only one so the names are cleaner.
> if (i == 1) {
> objName = new ObjectName(base + jmxNamePrefix);
> } else {
> objName = new ObjectName(base + jmxNamePrefix + i);
> }
> mbs.registerMBean(this, objName);
> objectName = objName;
> registered = true;
> } catch (MalformedObjectNameException e) {
> if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(
> jmxNamePrefix) && jmxNameBase.equals(base)) {
> // Shouldn't happen. Skip registration if it does.
> registered = true;
> } else {
> // Must be an invalid name. Use the defaults instead.
> jmxNamePrefix =
> BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
> base = jmxNameBase;
> }
> } catch (InstanceAlreadyExistsException e) {
> // Increment the index and try again
> i++;
> } catch (MBeanRegistrationException e) {
> // Shouldn't happen. Skip registration if it does.
> registered = true;
> } catch (NotCompliantMBeanException e) {
> // Shouldn't happen. Skip registration if it does.
> registered = true;
> }
> }
> return objectName;
> }
> {quote}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)