提交 439b1276 authored 作者: S.Vladykin's avatar S.Vladykin

Table.getNullRow() improved concurrency

上级 b2a70c1c
......@@ -6,6 +6,7 @@
package org.h2.table;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
......@@ -104,7 +105,7 @@ public abstract class Table extends SchemaObjectBase {
private ArrayList<TableView> views;
private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate;
private Row nullRow;
private volatile Row nullRow;
public Table(Schema schema, int id, String name, boolean persistIndexes,
boolean persistData) {
......@@ -616,14 +617,15 @@ public abstract class Table extends SchemaObjectBase {
return new SimpleRow(new Value[columns.length]);
}
synchronized Row getNullRow() {
if (nullRow == null) {
nullRow = new Row(new Value[columns.length], 1);
for (int i = 0; i < columns.length; i++) {
nullRow.setValue(i, ValueNull.INSTANCE);
}
Row getNullRow() {
Row row = nullRow;
if (row == null) {
// Here can be concurrently produced more than one row, but it must be ok.
Value[] values = new Value[columns.length];
Arrays.fill(values, ValueNull.INSTANCE);
nullRow = row = new Row(values, 1);
}
return nullRow;
return row;
}
public Column[] getColumns() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论