I am trying to save an entity to Google App Engine Datastore only if it does not exist, if it does the thread should not continue.

Main issue is: I want to prevent any race conditions, such that if 2 threads are doing this at the same time only one would succeed in saving the entity.

I am not sure what is the best approach for this, would using Transactions work or one must rely on other solutions such as using Memcache

Please provide answer in low level API in java