Originally posted by Tommy Wan:
I posted this question in this topic, and I got no response.
https://coderanch.com/t/186694/java-developer-SCJD/certification/does-Data-class-have-singleton
My question is,
If I create a singleton class Data, either network mode or local mode, only client can have one instance of Data, so only one client can work with the data file at any given time.
Do I still need synchoniation in this case?
Tommy
How does being a singleton limit the number of clients that can simultaneously use the Data class? Each client will have at least one
thread at any time its accessing the server. Each of those threads can be using that Data instance, its quite possible for there to be several using it at once. If you use a RandomAccessFile you will need to seek and read to get data and you don't want another thread to move that data pointer between the seek and the read. If you cache records you will need to synchronize access to the cache.
The simple answer is yes, you will have multiple threads and you will need synchronization.