Serialization vs Synchronization
Serialization is used whenever you try to store an object in a file or suppose
you want to transfer an object from one application to another application via
network in that case you serialize an object so whenever a object is serialize
it make sense because it can be transferred over the network and it can be
persisted. This is very important whenever data is transferred across the
network or you want to store it in a file right to a file. Synchronization is
whenever multiple thread that trying to access object or instance or method
then there might be problem for concurrency issues because it may happen that
once I just trying to modify the value of a variable and at the same time
another thread is trying to read it so in those cases we try to use
synchronized keyword over a block of code or over a method so that only one
thread can access that method at a time and all other threads have to wait so
only when this current thread exist the method and releases the control to
other threads in waiting.
In Other way:
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.
No comments:
Post a Comment