[
https://issues.apache.org/jira/browse/POOL-393?focusedWorklogId=681173&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-681173
]
ASF GitHub Bot logged work on POOL-393:
---------------------------------------
Author: ASF GitHub Bot
Created on: 13/Nov/21 23:01
Start Date: 13/Nov/21 23:01
Worklog Time Spent: 10m
Work Description: kinow commented on a change in pull request #115:
URL: https://github.com/apache/commons-pool/pull/115#discussion_r748775022
##########
File path:
src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
##########
@@ -62,6 +62,9 @@
*/
public abstract class BaseGenericObjectPool<T> extends BaseObject {
+ /** Suffix appended to name of the next pool to be registered with JMX */
+ private static final AtomicLong NEXT_POOL_SUFFIX = new AtomicLong();
Review comment:
At first didn't understand how that'd speed up the process, but the JIRA
issue had the answer, so for others that didn't read the issue before:
>In the code, the ObjectName's postfix always starts with 1, so many
InstanceAlreadyExistsExceptions may be thrown before registered successfully.
Simple solution, thanks for adding a test with a timeout too, +1!
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 681173)
Time Spent: 0.5h (was: 20m)
> 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
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
>
> When creating many 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)
> Unknown macro: \{ 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)
> Unknown macro: \{ objName = new ObjectName(base + jmxNamePrefix); }
> else
> Unknown macro: \{ 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))
> Unknown macro: \{ // Shouldn't happen. Skip registration if it does.
> registered = true; }
> else
> Unknown macro: \{ // Must be an invalid name. Use the defaults instead.
> jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX; base =
> jmxNameBase; }
> } catch (InstanceAlreadyExistsException e)
> Unknown macro: \{ // Increment the index and try again i++; }
> catch (MBeanRegistrationException e)
> Unknown macro: \{ // Shouldn't happen. Skip registration if it does.
> registered = true; }
> catch (NotCompliantMBeanException e)
> }
> return objectName;
> }
> {quote}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)