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

Table.getNullRow() improved concurrency

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