Search code examples
javaunsafe

Is sun.misc.Unsafe thread safe?


Is sun.misc.Unsafe or the theUnsafe instance thread safe?


Solution

  • The methods of Unsafe are not thread safe. You need to synchronize access to data you want to manipulate yourself - as usual. Accessing the instance theUnsafe however is, because the field gets initialized when the class is being loaded (it's static).