A record store is the only form of persistent storage that a CLDC device is required to support. A record store is a set of unformatted data elements, each identified by a unique integer. There are API calls to create and delete record stores, and to insert, remove, and search the elements. The elements themselves are exposed to the application as byte arrays, and if they are to have any internal structure, then the application must impose it. In this sense, records in a record store a like files, except that (1) the files are numbered, not named, and (2) each record element must be read or written in one operation.

Because CLDC applications can be multi-threaded, the use of record stores is a rare example of an occasion where concurrency management can be troublesome to a CLDC developer. The record store implementation will synchronise access to the external non-volatile memory to the extent that each read or write is atomic. However, there are no transactional semantics or locking in record stores. If one thread of execution reads the same record twice, and another thread modifies the record between the other threads two reads, then the two reads will get different values. Vendors of relational databases go to some lengths to protect against this sort of problem, but such measures would be difficult to implement in a CLDC device. It is therefore the developer's responsibility to ensure that different threads do not attempt to read and write the same records at the same time if this would upset the application logic.

 Related Tips