Sorry in advance for spelling errors
**
** I need to create a system in Java which synchronyzes a single text file in all the comuters in the system . In order to do it Ive created a server / Client to each computer, which links to all of his neighbors and checks who is the most uptadet file by using lastModified method.
A "probelm" that accured is when I get the file from my neighbor and update it, my lastModified is now bigger and thus he requsts the file from me- and so on a never ending loop, I've been suggested to solve it with setLastModified (I'm changing the lastModified time of my neighbor to mine) BUT it doesnt work ?!
I serched google and it says setLastModified sets modification times to the nearest second- is this the problem? how can I fix it / is their a method with more accuracy to set modification times?
if (neighborLastMod > file.lastModified()){
getFileFromNeighbor(neighbor.getip(),neighbor.getport(),neighborLastMod);
....
file.setLastModified(neighborLastMod);
The last modified time stamp is precise only up to one second anyway, so accuracy is not the problem.
A possible problem is that while you are getting the file from the neighbor the last modified time stamp is temporarily set to the current time. To fix this your getFileFromNeighbor
should save the file from the neighbor to a temporary file, set the last modified time stamp of the temporary file, and then do an atomic move or rename so that no system at any point sees a file with a higher time stamp.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다