phet commented on code in PR #3857:
URL: https://github.com/apache/gobblin/pull/3857#discussion_r1450988687
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/FlowSpec.java:
##########
@@ -75,13 +78,22 @@ public class FlowSpec implements Configurable, Spec {
/** Human-readable description of the flow spec */
final String description;
- /** Flow config as a typesafe config object */
- final Config config;
+ /* Note that since getConfig() and getConfigAsProperties() are independent
accessors, `volatile` doesn't ensure a
+ * consistent view between them. In a multi-threaded scenario one should use
the following access mechanism:
+ * FlowSpec fs = ...
+ * synchronized (fs) {
Review Comment:
I do agree it would be overkill in the general case, wherein the user is
only getting one or the other of the two. there's no need for a single
accessor to synchronize on the instance, given `volatile`.
what I believe urmi's suggesting is to lock the object if one wants to
access both. this ensures both sides agree. perhaps such clarification could
be added to the comment:
```
In a multi-threaded scenario one should use the following access mechanism:
```
?
it sounds overly broad as phrased above, given "a MT scenario" applies to
all our code everywhere.
the other important thing to mention is that the `synchronized` block should
only be small enough to obtain the two, so it doesn't keep the object locked.
the other alternative would be to add a combo method to this `FlowSpec`
derived class:
```
/** use for consistency between the two... */
public synchronized Pair<Config, Properties> getConfigAndProperties() {
// ultimate correctness would be to return a defensive copy of `Properties`
}
```
would this perhaps be clearest advice to give?
--
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]