Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between serialization and synchronization in java?

What is the difference between serialization and synchronization in java? I need an explanation or a tutorial.

like image 341
Praveen Avatar asked Dec 23 '25 01:12

Praveen


2 Answers

Synchronization refers to multi-threading. A synchronized block of code can only be executed by one thread at a time.

Serialization refers to converting objects to bitstreams either for storage or transmission. The act of serialization encodes the data according to specific rules. This bitstream can then be deserialized later or on a remote system that receives it. For serialization to work the class definition must match (i.e. you need to be using the same version of the class or one that is guaranteed to be compatible) and the class must implement the Serializable interface.

More on serialization.

More on synchronization

like image 60
Kris Avatar answered Dec 24 '25 15:12

Kris


Synchronization is a concurrency issue, e.g. how do you coordinate access to an object from multiple threads.

Here an arrow represents access.

                            s
 [thread1] ---------------> y
                            n [shared object]
 [thread2] ---------------> c
                            h

Serialization is the conversion of data structures and objects into a sequence of bits that you can store/transmit and then convert back to data structures and objects.

Here an arrow represents conversion.

            deserialization
           <---------------
  [object]                  [binary]
           --------------->
            serialization

This is most useful when the deserialization happens at another place and/or time.

like image 20
polygenelubricants Avatar answered Dec 24 '25 14:12

polygenelubricants



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!