[
https://issues.apache.org/jira/browse/CONFIGURATION-390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760122#action_12760122
]
Ralph Goers commented on CONFIGURATION-390:
-------------------------------------------
I have committed my changes to
https://svn.apache.org/repos/asf/commons/proper/configuration/branches/CONFIGURATION_390.
Please inspect the changes and test.
1. CombinedConfiguration and SubnodeConfiguration both extend
HierarchicalReloadableConfiguration.
2. HierarchicalReloadableConfiguration implements Reloadable.
3. AbstractHierarchicalFileConfiguration implements Reloadable as
delegate.getReloadLock().
4. AbstractHierarchicalFileConfiguration wraps many of the methods with
synchronized(delegate.getReloadLock()).
5. HierarchicalReloadableConfiguration has a constructor that can be passed the
lock to synchronize on. If no lock is passed a new Object is used.
6. SubnodeConfiguration's constructor gets the parents lock object if the
parent is Reloadable and passes it to HierarchicalReloadableConfiguraton's
constructor. This should cause any SubnodeConfiguration for XMLConfiguration or
CombinedConfiguration to use the lock of its parent.
> AbstractHierarchicalFileConfiguration is not thread safe
> --------------------------------------------------------
>
> Key: CONFIGURATION-390
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-390
> Project: Commons Configuration
> Issue Type: Bug
> Components: File reloading
> Affects Versions: 1.6
> Reporter: Emmanuel Bourg
> Fix For: 1.7
>
> Attachments: commons-configuration-390.patch, configtest.tar.gz,
> TestSuite.txt
>
>
> AbstractHierarchicalFileConfiguration doesn't implement the same locking
> mechanism found in AbstractFileConfiguration. The consequence is that getting
> a property while the configuration is being reloaded by another thread can
> return an invalid result.
> This can be demonstrated by changing testDeadlockWithReload() in
> TestCombinedConfiguration to use an XMLConfiguration instead of a
> PropertiesConfiguration.
> Here is a reduced test case:
> {code:java}
> public void testConcurrentGetAndReload() throws Exception
> {
> //final FileConfiguration config = new
> PropertiesConfiguration("test.properties");
> final FileConfiguration config = new XMLConfiguration("test.xml");
> config.setReloadingStrategy(new FileAlwaysReloadingStrategy());
> assertTrue("Property not found", config.getProperty("test.short") !=
> null);
> new Thread()
> {
> public void run()
> {
> for (int i = 0; i < 1000; i++)
> {
> config.reload();
> }
> }
> }.start();
>
> for (int i = 0; i < 1000; i++)
> {
> assertTrue("Property not found", config.getProperty("test.short") !=
> null); // failure here
> }
> }
> {code}
> The test doesn't always fail. It does about 50% of the time.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.