Thinking in JAVA第四版源代码

源代码在线查看: filelocking.java

软件大小: 543 K
上传用户: wanglp094
关键词: Thinking JAVA in 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: io/FileLocking.java
				import java.nio.channels.*;
				import java.util.concurrent.*;
				import java.io.*;
				
				public class FileLocking {
				  public static void main(String[] args) throws Exception {
				    FileOutputStream fos= new FileOutputStream("file.txt");
				    FileLock fl = fos.getChannel().tryLock();
				    if(fl != null) {
				      System.out.println("Locked File");
				      TimeUnit.MILLISECONDS.sleep(100);
				      fl.release();
				      System.out.println("Released Lock");
				    }
				    fos.close();
				  }
				} /* Output:
				Locked File
				Released Lock
				*///:~
							

相关资源