• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized block strategy for data file

 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Just so i can make operation to the data file thread-safe and efficient at the same time, i've decided to put access to the datafile in a synchronized block and if i want further use of somme bytes in the datafile i will place them first in a datainputstream for access.

Something like:



Is there something wrong with this code?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

What is the scope of your recordStream variable?

What difference does the following change make?Regards, Andrew
 
Yupp Cook
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

What's the advantage of using those streams? I think all necessary operations can be done just using the RandomAccessFile object.

Yupp
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Yes, you're right, I should do that. But since i see you not commenting on the datainputstream then i would say this is a good solution, right?

Hi Yupp,

The reason why i wanted to use datainputstream is for me to be able to make the operations in datafile thread-safe and requires at once and then make the necessary reads without synchronize it.

regards,
tim
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim
But since i see you not commenting on the datainputstream then i would say this is a good solution, right?
It can be a good solution. It does not work for all assignments, so it is not one that we often see discussed. But if it works for you then go for it!

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic