首页 » 技术分享 » 同步测试

同步测试

 

public FileLock(String lockFileName, String content) {
  file = new File(lockFileName);
 }out = new FileOutputStream(file, true);
    channel = out.getChannel();    
    lock = channel.tryLock();    
    while (lock == null) {
     System.out.println("重试。。。");
     Thread.sleep(3000);
     //this.wait();
     lock = channel.tryLock();
    }
    
    byte[] bs = content.getBytes();
    out.write(bs, 0, bs.length);
    out.flush();
    content = (content.equals("第一个")) ? "第二个" : "第三个";

    Thread.sleep(3000);
    //notifyAll();

lock.release();

转载自原文链接, 如需删除请联系管理员。

原文链接:同步测试,转载请注明来源!

0