[Composite Datasource]: Custom Java Datastore

Attached is a simple example that dumps the output from the datastore to the console.

Please change the following file format from .txt to .java
SampleJavaStore.txt (2.6 KB)

The documentation that describes the interfaces is shown in the Data Designer manual Chapter 10 Object DataSource → Object DataSource API → DataListener and there are some comments shown in the source code as well.

A very common question which was asked about the Custom Java DataStore is: Is the custom Java DataStore thread-safe ?

Thread safety is an issue when multiple threads have access to shared resources. In the case of our DataStores, each DataStore instance is only accessible by one thread, so thread safety isn’t an issue.

However, let’s take custom Java DataStore as an example:

There is one class MyDS.class which is my custom datastore.

Case 1/ The user runs two separate composites, each which reference MyDS.
Case 2/ The user runs the same composite twice

In each case we will assume that both runs are in parallel - the user creates two threads and calls GenerateData in both of them.

Case 1/ Each composite (running in a separate thread) will create an instance of MyDS
Case 2/ Each composite instance will create an instance of MyDS

In both cases, we aren’t concerned about thread safety because there is no sharing of instances between threads.

In general: every call to GenerateData will create an instance of the Composite which will create an instance of MyDS. No sharing.

However if the writer of MyDS isn’t aware of thread safety they might use static variables in MyDS which will be shared. It is possible to write a custom DataStore that isn’t threaded safe