我想通过线程在同一个文件中读写。
但条件是当第一个线程完成读取时,另一个线程应该写入。
我提出的解决方案是:
class XYX {
public void read(){
synchronised(fileObj){
//write the reading logic
}
}
public void write(){
synchronised(fileObj){
//write the writing logic
}
}
}
请让我知道你的想法
我想保留这个订单
阅读 - 写作 - 阅读 - 写作 - 阅读 - 等等