Skip to content

Commit 90e6735

Browse files
committed
refactor WrappingReportTable
1 parent 64d4f66 commit 90e6735

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/org/spacious_team/broker/report_parser/api/WrappingReportTable.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,30 @@ public EagerWrappingReportTable(BrokerReport report, Collection<RowType>... data
8181
}
8282
}
8383

84-
@RequiredArgsConstructor
8584
private static class LazyWrappingReportTable<RowType> implements ReportTable<RowType> {
8685
@Getter
8786
private final BrokerReport report;
88-
private final ReportTable<RowType>[] tables;
87+
private volatile ReportTable<RowType>[] tables;
8988
private volatile List<RowType> data;
9089

90+
@SafeVarargs
91+
private LazyWrappingReportTable(BrokerReport report, ReportTable<RowType>... tables) {
92+
this.report = report;
93+
this.tables = tables;
94+
}
95+
9196
@Override
9297
public List<RowType> getData() {
9398
if (data == null) {
94-
data = Arrays.stream(tables)
95-
.map(ReportTable::getData)
96-
.flatMap(Collection::stream)
97-
.collect(Collectors.toUnmodifiableList());
99+
synchronized (this) {
100+
if (data == null) {
101+
data = Arrays.stream(tables)
102+
.map(ReportTable::getData)
103+
.flatMap(Collection::stream)
104+
.collect(Collectors.toUnmodifiableList());
105+
tables = null; // erase for GC
106+
}
107+
}
98108
}
99109
return data;
100110
}

0 commit comments

Comments
 (0)