Skip to content

Commit c74f401

Browse files
authored
Merge pull request #183 from rzabini/pr-base
B Make WithTimeZone thread safe
2 parents acbdac3 + 4489bcd commit c74f401

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
junit.jupiter.execution.parallel.enabled=true
2+
junit.jupiter.execution.parallel.mode.default = concurrent
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package org.approvaltests.utils;
22

33
import java.util.TimeZone;
4+
import java.util.concurrent.locks.ReentrantLock;
45

56
public class WithTimeZone implements AutoCloseable
67
{
7-
private final TimeZone tz;
8+
private static final ReentrantLock defaultTimeZoneLock = new ReentrantLock();
9+
private final TimeZone tz;
810
public WithTimeZone()
911
{
1012
this("UTC");
1113
}
1214
public WithTimeZone(String zoneId)
1315
{
1416
tz = TimeZone.getDefault();
17+
defaultTimeZoneLock.lock();
1518
TimeZone.setDefault(TimeZone.getTimeZone(zoneId));
1619
}
1720
@Override
1821
public void close()
1922
{
2023
TimeZone.setDefault(tz);
24+
defaultTimeZoneLock.unlock();
2125
}
2226
}

0 commit comments

Comments
 (0)