0
我有一個文件,SI從文件夾中讀取,但是我的應用程序部署在兩個羣集上,因此文件正在讀取兩次,因此我使用了春季提供的文件鎖定機制但在這種情況下,我發現我的文件根本沒有處理。我錯過了什麼?如何使用SI中提供的文件鎖定機制來讀取文件
UPDATE:我使用FileLocker類以這種方式使用FileInbound適配器
private FileInboundChannelAdapterSpec readFilefromDirectory(){
return Files.inboundAdapter(getInboxDirectory())
.autoCreateDirectory(true)
.locker(asFileLocker)
.preventDuplicates();
}
@Component
public class ASFileLocker implements FileLocker{
@Autowired
Properties properties;
@Override
public boolean lock(File fileToLock) {
try{
if(properties.getProperty("fileName").equalsIgnoreCase(fileToLock.getName())){
return false;
}
else{
properties.setProperty("fileName", fileToLock.getName());
return true;
}
}catch(Exception e){
return false;
}
}
@Override
public boolean isLockable(File file) {
String fileName= properties.getProperty("fileName");
if(fileName.equalsIgnoreCase(file.getName())){
return true;
}
else{
return false;
}
}
@Override
public void unlock(File fileToUnlock) {
}
我已更新我的問題與代碼,我使用.is這是正確的? –
你的代碼沒有意義。它不鎖定任何內容,也不是線程安全的。爲什麼不按照建議,不要使用'FileSystemPersistentAcceptOnceFileListFilter':http://docs.spring.io/spring-integration/reference/html/files.html#file-reading? –