[concurrency-interest] thread safety of java.lang.reflect.Field
novitools.novi at web.de
Thu May 31 10:35:08 EDT 2018
> I have not had any trouble with multiple threads using Fields
Neither do I but that is no guarantee for correctness.
(Compare for example this reflection related issue:
> In other words, one still has to be mindful of concurrent access to the
> object's fields.
That is true but it is not what I meant to ask.
Assuming that j.l.r.Field is thread safe in the current OpenJDK version,
merely an implementation detail or something that is guaranteed in future
and/or other JVM implementations?
Am 31.05.2018, 14:11 Uhr, schrieb Nathan and Ila Reynolds via
Concurrency-interest <concurrency-interest at cs.oswego.edu>:
> I usually cache Fields in private static final fields in the class that
> I use the Fields. I have not had any trouble with multiple threads
> using Fields concurrently. One caution is that if two threads execute
> the statement below concurrently on the same "obj", then one of the
> increments could be lost. In other words, one still has to be mindful
> of concurrent access to the object's fields.
> s_field.setInt(obj, s_field.getInt(obj) + 1);
> On 5/31/2018 3:31 AM, Novi via Concurrency-interest wrote:
>> I wonder if instances of java.lang.reflect.Field can be shared between
>> multiple threads as long as the accessibility flag is either not
>> or modified exactly once prior to a safe publication of the field
>> In other words, is it legal to cache instances of j.l.r.Field between
>> multiple threads?
>> Best Regards,
>> PS: The Bean Validation reference implementation Hibernate Validator
>> to cache instances of j.l.r.Field across threads. However, I couldn't
>> find any
>> clue in the Java API documentation whether such a usage is supported or
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
More information about the Concurrency-interest