Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 57D25200BCD for ; Sun, 27 Nov 2016 18:14:47 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 55AD0160B12; Sun, 27 Nov 2016 17:14:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7A3DA160B01 for ; Sun, 27 Nov 2016 18:14:46 +0100 (CET) Received: (qmail 4012 invoked by uid 500); 27 Nov 2016 17:14:45 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 4001 invoked by uid 99); 27 Nov 2016 17:14:44 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Nov 2016 17:14:44 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6F3181A00B6 for ; Sun, 27 Nov 2016 17:14:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.299 X-Spam-Level: ** X-Spam-Status: No, score=2.299 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id QOqMxZNiL35c for ; Sun, 27 Nov 2016 17:14:41 +0000 (UTC) Received: from mxout-07.mxes.net (mxout-07.mxes.net [216.86.168.182]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id DFC865F256 for ; Sun, 27 Nov 2016 17:14:40 +0000 (UTC) Received: from [192.168.1.112] (unknown [50.184.0.250]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 23FC722E256; Sun, 27 Nov 2016 12:14:33 -0500 (EST) Subject: Re: [configuration] tension between auto-loading and synchronization To: Gary Gregory , Commons Users List References: From: Garret Wilson Organization: GlobalMentor, Inc. Message-ID: Date: Sun, 27 Nov 2016 09:14:33 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E42865F97B61C3A12D8621B1" archived-at: Sun, 27 Nov 2016 17:14:47 -0000 --------------E42865F97B61C3A12D8621B1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for clearing this up, Oliver! I was going straight from the documentation. On the page https://commons.apache.org/proper/commons-configuration/userguide/howto_concurrency.html I can't find anything about setting up the builder parameters. So I'm extremely happy to learn that you can configure the builder with a synchronizer. So I guess the "tension" now is that part of the documentation says, "it's better to use a builder than the configuration itself, especially if you want auto-loading", and then the part that actually talks about synchronization seems to favor working with the configuration and doesn't even mention that I can set the synchronizer on the builder. At the very least https://commons.apache.org/proper/commons-configuration/userguide/howto_concurrency.html should mention the configuration params. Cheers, Garret On 11/27/2016 8:58 AM, Gary Gregory wrote: > > Do we need better Javadocs to make this obvious? > > Gary > > > On Nov 27, 2016 7:02 AM, "Oliver Heger" > wrote: > > Hi, > > Am 25.11.2016 um 22:55 schrieb Garret Wilson: > > I'm reading the documentation for the new > commons-configuration 2.x. I > have a simple need: load a configuration file from a > properties file, > reload it when the file changes, and make the configuration > thread-safe > for reading. > > From the documentation I understand that I shouldn't keep the > Configuration object around, because it may be reloaded if the > file > changes. Instead I should keep a ConfigurationBuilder around. > So my > application's getConfiguration() would look like this: > > public Configuration getConfiguration() { > return configurationBuilder.getConfiguration(); > } > > But I need it to be thread-safe. So I do this: > > public Configuration getConfiguration() { > Configuration > configuration=configurationBuilder.getConfiguration(); > configuration.setSynchronizer(new ReadWriteSynchronizer()); > return configuration; > } > > Oops! It turns out that we don't know if the builder returns > the same > configuration or a new configuration, so we could be swapping > out the > synchronizer on the same configuration. That introduces a race > condition > and defeats the thread safety! > > So are we expected to keep a separate synchronizer around and > make sure > the new/existing configuration uses it? > > private final Synchronizer synchronizer = new > ReadWriteSynchronizer(); > > public Configuration getConfiguration() { > Configuration > configuration=configurationBuilder.getConfiguration(); > configuration.setSynchronizer(synchronizer); > return configuration; > } > > Wow, that's getting complicated. The problem is that Apache > Commons > Configuration2 recommends that the builder be the ultimate > source of the > configuration, yet it associates the syncrhonizer with the actual > configuration instance. Shouldn't we set the synchronizer on > the builder > and let it manage the synchronizer of the new configurations? > Or do you > want each configuration to potentially have different > synchronizers? But > is that realistic---would synchronized and unsynchronized > configurations > play well together if they are backed by the same builder? I'm > trying to > understand what the expected usage is. > > > you configure the builder to set the correct synchronizer on newly > created Configuration objects. To achieve this, call the builder's > configure() method with a parameters object. Focused on the > synchronizer, this looks as follows: > > Synchronizer sync = ...; > Parameters params = new Parameters(); > BasicConfigurationBuilder builder = > new BasicConfigurationBuilder( > PropertiesConfiguration.class) > .configure(params.basic() > .setSynchronizer(sync)); > > Just insert your type parameters for the configuration type. All > properties configured this way are automatically set on the > Configuration each time a new instance is created. > > Oliver > > > Garret > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > > For additional commands, e-mail: user-help@commons.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > > For additional commands, e-mail: user-help@commons.apache.org > > --------------E42865F97B61C3A12D8621B1--