New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JdbiUtil: use concurrent data structure to store static state #2341
Conversation
|
||
import org.jdbi.v3.core.Handle; | ||
import org.jdbi.v3.core.Jdbi; | ||
import org.jdbi.v3.core.internal.UtilityClassException; | ||
import org.springframework.transaction.support.TransactionSynchronizationAdapter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is deprecated for removal.
import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
||
/** | ||
* Utility for working with Jdbi and Spring transaction bound resources | ||
*/ | ||
public class JdbiUtil { | ||
private static final Set<Handle> TRANSACTIONAL_HANDLES = new HashSet<>(); | ||
private static final Set<Handle> TRANSACTIONAL_HANDLES = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am cool with this, but we did use CopyOnWriteSet in other places where concurrency was required.
RELEASE_NOTES.md
Outdated
@@ -1,4 +1,5 @@ | |||
# Unreleased | |||
- spring5 JdbiUtil: fix thread safety |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a reference to the issue that this addresses
Right, unless I am missing something, this is quite different. The copy on write map is useful with mostly immutable config where the most common operation is copying the map. In this case we never copy, we are just adding and removing elements to a single static collection, which is a better fit for a normal concurrent map. On May 3, 2023, at 6:40 PM, Henning Schmiedehausen ***@***.***> wrote:
@hgschmie commented on this pull request.
In spring5/src/main/java/org/jdbi/v3/spring5/JdbiUtil.java:
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* Utility for working with Jdbi and Spring transaction bound resources
*/
public class JdbiUtil {
- private static final Set<Handle> TRANSACTIONAL_HANDLES = new HashSet<>();
+ private static final Set<Handle> TRANSACTIONAL_HANDLES = Collections.newSetFromMap(new ConcurrentHashMap<>());
I am cool with this, but we did use CopyOnWriteSet in other places where concurrency was required.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
86cf8ed
to
f371899
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Fixes #2336