Hello Java-Gurus!
I have some questions about the synchronization.
I have one class, say Database. This class makes some I/O action with the file (RandomAccessFile). I synchronize every method, that works with the RandomAccessFile instance.
In the another class, say MyClass I use this Database instance to write or read from the file.
Every
thread becomes its own version of the MyClass instance, but they will be work with the
same instance of the Database. I make this instance private static.
This looks like:
I synchronize the database instance, to avoid that two or more threads will be work with the database concurrently.
For example the first thread wants to call the write method and put the file pointer at position 10. The second wants
to write some data at the position 20 of the file. To avoit this I synchronize the instance of the database in MyClass.
My question is, is this thread save?
Or is this nested synchronization, that I need to avoid it?
Will this the second implementation more correct:
Could you help the greenhorn in multi-thread/synchronization world?
What is the best way to implement it?
Thanks a lot for your help!
Regards,
Olena