同步测试

来源:互联网 发布:python 数组排序sort 编辑:程序博客网 时间:2024/04/30 00:24

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