0
volatile, synchronized, and transient
Anyone knows the difference and implementation of those keywords in Java?
1 Respuesta
+ 1
Those are actually really specific keywords that I doubt you'll really need, but I'll tell you what they mean:
First, transient. If you make a class that implements java.io.Serializable, then all objects within that class must also implement Serializable. If a class doesn't do that, then in order to use it within the class, you have to mark it as transient.
The volatile keyword is used with threads. If a variable within a thread is volatile, it means that methods outside the thread can access and modify it.
Finally, the synchronized keyword is a little more complicated. Sometimes you'll have two threads that access the same method. If that happens, then the threads could end up conflicting with one another. The synchronized keyword prevents that from happening by only allowing one thread at a time to access what's in a particular section of code.