Skip to content

Commit 9e96650

Browse files
authored
docs: Marking Transaction, Batch and DatastoreBatchWriter class with 'NotThreadSafe' annotation (#1082)
* doc: Marking Transaction, Batch and DatastoreBatchWriter class with @NotThreadSafe annotation * fix lint * adding jsr dependency explicitly * Empty commit * fixing casing and punctuation. * fix lint
1 parent 95455e0 commit 9e96650

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

google-cloud-datastore/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
<groupId>io.opencensus</groupId>
107107
<artifactId>opencensus-api</artifactId>
108108
</dependency>
109+
<dependency>
110+
<groupId>com.google.code.findbugs</groupId>
111+
<artifactId>jsr305</artifactId>
112+
</dependency>
109113

110114
<!-- Test dependencies -->
111115
<dependency>

google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.datastore;
1818

1919
import java.util.List;
20+
import javax.annotation.concurrent.NotThreadSafe;
2021

2122
/**
2223
* An interface to represent a batch of write operations. Any write operation that is applied on a
@@ -32,7 +33,15 @@
3233
* batch.add(entity2, entity3);
3334
* batch.submit();
3435
* }</pre>
36+
*
37+
* <p><b> WARNING: This class maintains an internal state in terms of {@link
38+
* java.util.LinkedHashMap} and {@link java.util.LinkedHashSet} which gets updated on every method
39+
* call performing CRUD operations to record the mutations. Since {@link java.util.LinkedHashMap} is
40+
* not thread safe as per its <a
41+
* href="https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html">documentation</a>,
42+
* This class too should not be treated as a thread safe class. </b>
3543
*/
44+
@NotThreadSafe
3645
public interface Batch extends DatastoreBatchWriter {
3746

3847
interface Response {

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717
package com.google.cloud.datastore;
1818

1919
import java.util.List;
20+
import javax.annotation.concurrent.NotThreadSafe;
2021

2122
/**
2223
* An interface to represent a batch of write operations. All write operation for a batch writer
2324
* will be applied to the Datastore in one RPC call.
25+
*
26+
* <p><b> WARNING: This class maintains an internal state in terms of {@link
27+
* java.util.LinkedHashMap} and {@link java.util.LinkedHashSet} which gets updated on every method
28+
* call performing CRUD operations to record the mutations. Since {@link java.util.LinkedHashMap} is
29+
* not thread safe as per its <a
30+
* href="https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html">documentation</a>,
31+
* This class too should not be treated as a thread safe class. </b>
2432
*/
33+
@NotThreadSafe
2534
public interface DatastoreBatchWriter extends DatastoreWriter {
2635

2736
/**

google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
import com.google.protobuf.ByteString;
2020
import java.util.Iterator;
2121
import java.util.List;
22+
import javax.annotation.concurrent.NotThreadSafe;
2223

2324
/**
2425
* A Google cloud datastore transaction. Similar to {@link Batch} any write operation that is
2526
* applied on a transaction will only be sent to the Datastore upon {@link #commit}. A call to
2627
* {@link #rollback} will invalidate the transaction and discard the changes. Any read operation
2728
* that is done by a transaction will be part of it and therefore a {@code commit} is guaranteed to
28-
* fail if an entity was modified outside of the transaction after it was read. Write operation on
29-
* this transaction will not be reflected by read operation (as the changes are only sent to the
29+
* fail if an entity was modified outside the transaction after it was read. Write operation on this
30+
* transaction will not be reflected by read operation (as the changes are only sent to the
3031
* Datastore upon {@code commit}. A usage example:
3132
*
3233
* <pre>{@code
@@ -52,7 +53,14 @@
5253
*
5354
* @see <a href="https://cloud.google.com/datastore/docs/concepts/transactions">Google Cloud
5455
* Datastore transactions</a>
56+
* <p><b> WARNING: This class maintains an internal state in terms of {@link
57+
* java.util.LinkedHashMap} and {@link java.util.LinkedHashSet} which gets updated on every
58+
* method call performing CRUD operations to record the mutations. Since {@link
59+
* java.util.LinkedHashMap} is not thread safe as per its <a
60+
* href="https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html">documentation</a>,
61+
* This class too should not be treated as a thread safe class. </b>
5562
*/
63+
@NotThreadSafe
5664
public interface Transaction extends DatastoreBatchWriter, DatastoreReaderWriter {
5765

5866
interface Response {

0 commit comments

Comments
 (0)