Skip to content

Commit

Permalink
Merge #184 manually (fails clean merge due to refactor b/w 2.x and 3.…
Browse files Browse the repository at this point in the history
…0) (#185)
  • Loading branch information
cowtowncoder committed Apr 1, 2024
1 parent 35c53f8 commit 130c166
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Expand Up @@ -2,6 +2,7 @@

import java.util.EnumMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import tools.jackson.databind.*;
import tools.jackson.databind.cfg.MapperBuilder;
Expand All @@ -17,6 +18,8 @@ public abstract class MapperConfiguratorBase<IMPL extends MapperConfiguratorBase
MAPPER extends ObjectMapper
>
{
private final ReentrantLock _lock = new ReentrantLock();

/*
/**********************************************************************
/* Configuration, simple features
Expand Down Expand Up @@ -87,9 +90,14 @@ public MapperConfiguratorBase(MAPPER mapper,
_instropectorOverride = instropectorOverride;
}

public synchronized MAPPER getDefaultMapper() {
public MAPPER getDefaultMapper() {
if (_defaultMapper == null) {
_defaultMapper = _mapperWithConfiguration(mapperBuilder());
_lock.lock();
try {
_defaultMapper = _mapperWithConfiguration(mapperBuilder());
} finally {
_lock.unlock();
}
}
return _defaultMapper;
}
Expand All @@ -102,7 +110,12 @@ public synchronized MAPPER getDefaultMapper() {
protected MAPPER mapper()
{
if (_mapper == null) {
_mapper = _mapperWithConfiguration(mapperBuilder());
_lock.lock();
try {
_mapper = _mapperWithConfiguration(mapperBuilder());
} finally {
_lock.unlock();
}
}
return _mapper;
}
Expand All @@ -127,17 +140,17 @@ protected MAPPER mapper()
/**
* Method that locates, configures and returns {@link ObjectMapper} to use
*/
public synchronized MAPPER getConfiguredMapper() {
public MAPPER getConfiguredMapper() {
// important: should NOT call mapper(); needs to return null
// if no instance has been passed or constructed
return _mapper;
}

public synchronized final void setMapper(MAPPER m) {
public final void setMapper(MAPPER m) {
_mapper = m;
}

public synchronized final void setAnnotationIntrospector(AnnotationIntrospector aiOverride) {
public final void setAnnotationIntrospector(AnnotationIntrospector aiOverride) {
_instropectorOverride = aiOverride;
}

Expand Down
2 changes: 2 additions & 0 deletions release-notes/CREDITS-2.x
Expand Up @@ -91,6 +91,8 @@ PJ Fanning (@pjfanning)
* Contributed #166: `ProviderBase` class shows contention on synchronized
block using `LRUMap` _writers instance
(2.14.2)
* Contributed #184: Use `ReentrantLock`s instead of synchronized blocks
(2.18.0)

Steven Schlansker (@stevenschlansker)

Expand Down
3 changes: 2 additions & 1 deletion release-notes/VERSION-2.x
Expand Up @@ -12,7 +12,8 @@ Sub-modules:

2.18.0 (not yet released)

No changes since 2.17
#184: Use `ReentrantLock`s instead of synchronized blocks
(contributed by @pjfanning)

2.17.0 (12-Mar-2024)

Expand Down

0 comments on commit 130c166

Please sign in to comment.