我使用 JSCH 库创建了一个用于读取和写入远程位置属性文件的应用程序。
我想同步写操作。
这是我的代码,
class WebApp{
private String webappName;
private boolean isQA = false;
private String path ;
public WebApp(String name , String path , boolean isQA){
this.webappName = name;
this.path = path;
this.isQA = isQA;
}
public String getWebappName() {
return webappName;
}
public void setWebappName(String webappName) {
this.webappName = webappName;
}
public boolean isQA() {
return isQA;
}
public void setQA(boolean isQA) {
this.isQA = isQA;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
class WebAppProperty implements Runnable{
private WebApp webapp; // webapp-1
private String propertyFile; // server.properties
private String keyValue;
public String getPropertyFile() {
return propertyFile;
}
public void setPropertyFile(String propertyFile) {
this.propertyFile = propertyFile;
}
@Override
public void run(){
writeToPropertyFile();
}
public WebAppProperty(WebApp webapp , String propertyFile,String keyValue){
this.webapp = webapp;
this.propertyFile = propertyFile;
this.keyValue = keyValue;
}
private void writeToPropertyFile(){
try{
// code for writing key value pair into remote file
}catch (Exception e) {
}
}
}
这就是我要的
如果用户尝试写入 Web 应用程序上的属性文件说“A”,则尝试写入同一个 Web 应用程序的同一文件的所有其他用户应该等待,但另一个用户可以写入同一个 Web 应用程序或文件的另一个文件在另一个 webapp 上具有相同的名称。
同步方法可以完成所有这些工作吗?它如何识别 webapp 和属性文件?
我们需要同步读写操作吗?
如何在这种情况下实现锁定?
注意:我看到了关于并发的不同问题,但这些问题并没有消除我的疑虑,这就是为什么要问新问题,请帮助我对此进行澄清