setLastModified - Java

Idan Touito

Sorry in advance for spelling errors

**

  • Introduction to the project

** 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.

  • The Problem

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); 
Joni

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Interop : Java <-> Java

분류에서Dev

Java operators ||, -, /, +

분류에서Dev

=- operator in java

분류에서Dev

NullPointerException in Java

분류에서Dev

Java - BoxLayout

분류에서Dev

Java obfuscator?

분류에서Dev

JAVA java.util.ConcurrentModificationException

분류에서Dev

Java convert hex string to java: char[] (C) to byte[] (JAVA)

분류에서Dev

java.lang.NullPointerException in Java Swing code

분류에서Dev

Android Java의 java.lang.NullPointerException

분류에서Dev

Java Web Start 설치 : Java 12

분류에서Dev

java ejb java.rmi.UnknownHostException

분류에서Dev

java.lang.OutOfMemoryError: Java heap space

분류에서Dev

java.lang.NoSuchFieldError : IBM_JAVA

분류에서Dev

Sqlite Java 및 sqlite4java

분류에서Dev

Sqlite Java 및 sqlite4java

분류에서Dev

KNIME - Java snippet - DoubleCell/Java type double []

분류에서Dev

Java "java.lang.NoSuchMethodError: main"

분류에서Dev

Communicating Between Java SE and Java EE Applications

분류에서Dev

/ usr / bin / java의 Java 위치

분류에서Dev

java -jar 및 java.lang.NoClassDefFoundError

분류에서Dev

Java : A pipe used in a print statement in java?

분류에서Dev

Java 8-Java 7 코드

분류에서Dev

Java java.time.format.DateTimeParseException on String

분류에서Dev

GWT Java itextpdf-java.security.AccessControlException

분류에서Dev

Selenium (Java), java.lang.AssertionError

분류에서Dev

Java CLASSPATH 설정

분류에서Dev

Oracle Java (JDK) repository

분류에서Dev

Install java Runtime Environment