When do I need to use transactions?

Julien SIMON

You need to use transactions anytime you're modifying a set of data, which could end up in a weird state if the modifications don't run to completion.

For example, changing the value of a PIN needs to be transactioned: you wouldn't want to change only the first two bytes, would you?

Another example: when an account is credited, another is debited from the same amount. Crediting the first account and debiting the second account must be performed atomically.

A number of Java Card APIs use the transaction facility. The most notable is javacard.framework.arrayCopy().

You don't need to use transactions when you're modifying a single primitive value (primitive types, one cell of an array of primitive types). The Java Card platform guarantees that these writes are atomic. However, please note that a set of atomic writes is not itself atomic, hence the need for transactions!

About | Sitemap | Contact