Skip to content

Commit ccea6c1

Browse files
committed
docs: Add Parser concurrency note
1 parent 448a65b commit ccea6c1

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

module/jsonurl-factory/src/main/java/org/jsonurl/factory/ValueFactoryParser.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727

2828
/**
2929
* Concrete implementation of {@link Parser}.
30+
*
31+
* <h2>Concurrency</h2>
32+
*
33+
* <p>Each instance of {@code ValueFactoryParser} stores references to a
34+
* {@link ValueFactory},
35+
* a set of {@link org.jsonurl.JsonUrlOption JsonUrlOptions},
36+
* and {@linkplain org.jsonurl.JsonUrlLimits JsonUrlLimits}.
37+
* The state of each call to the {@link #parse(CharSequence)} method (or one
38+
* of its variants) is local. That means it is technically safe to reuse a
39+
* {@code ValueFactoryParser} across multiple threads. However, the parser does
40+
* provide access to its set of {@link #options()}, via a reference to a
41+
* mutable set. That means that it's possible to change the set by doing
42+
* something like:
43+
* <pre>JsonUrlParser p = ...;
44+
*p.options().add(JsonUrlOption.SKIP_NULLS);</pre>
45+
* Therefore, reusing a {@code ValueFactoryParser} is not recommended.
46+
* Because this object it so lightweight, and you're unlikely to realize any
47+
* real world benefit, you're better off simply creating a new instance each
48+
* time you need one.
3049
* @author jsonurl.org
3150
* @author David MacCormack
3251
* @since 2019-09-01

module/jsonurl-factory/src/main/java/org/jsonurl/j2se/JsonUrlParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
/**
2929
* A {@link org.jsonurl.factory.Parser Parser} bound to Java SE data types.
3030
*
31+
* <p>See {@link org.jsonurl.factory.ValueFactoryParser ValueFactoryParser}
32+
* for a note regarding concurrency.
33+
*
3134
* @author jsonurl.org
3235
* @author David MacCormack
3336
* @since 2019-09-01

module/jsonurl-jsonorg/src/main/java/org/jsonurl/jsonorg/JsonUrlParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* A <a href="https://jsonurl.org/">JSON&#x2192;URL</a> parser bound to
3030
* Douglas Crockford's original Java implementation of JSON.
3131
*
32+
* <p>See {@link org.jsonurl.factory.ValueFactoryParser ValueFactoryParser}
33+
* for a note regarding concurrency.
34+
*
3235
* @author jsonurl.org
3336
* @author David MacCormack
3437
* @since 2019-09-01

module/jsonurl-jsr374/src/main/java/org/jsonurl/jsonp/JsonUrlParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* A <a href="https://jsonurl.org/">JSON&#x2192;URL</a> parser bound to the
3636
* JSON-P interface defined by JSR-374.
3737
*
38+
* <p>See {@link org.jsonurl.factory.ValueFactoryParser ValueFactoryParser}
39+
* for a note regarding concurrency.
40+
*
3841
* @author jsonurl.org
3942
* @author David MacCormack
4043
* @since 2019-09-01

0 commit comments

Comments
 (0)