You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/05/12 22:42:05 UTC

[GitHub] [maven] Tibor17 commented on pull request #413: [MNG-6843] Thread-safe artifacts in MavenProject

Tibor17 commented on pull request #413:
URL: https://github.com/apache/maven/pull/413#issuecomment-840140360


   Why we do it so complicated? The threads do not share their objects with ThreadLocal-s. So every Thread will see another copy.
   If I was fixing this issue, I would use thread-safe collections and `synchronized` critical section `setArtifacts()` because first you have to clear the collection and then set new content in the critical section. That's it.
   But I am convinced that the issues in Maven are due to Java Memory Model that objects in `ArrayList` are weakly consistent. So you have to use the COWAL collection instead. Example, even if you use any treatment in this class, you pass a reference of the Set to the setter `setArtifacts()` you still may have a problem because the caller thread used thread-unsafe `Set`. So the caller must create ideally immutable Set or thread safe Set. If a copy of the content is acceptable then refuse copying the reference and the caller can be any thread unsafe object.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org