filelist.java
来自「JAVA实现的网络服务器文件同步」· Java 代码 · 共 56 行
JAVA
56 行
package com.msd;
import java.util.List;
import java.util.LinkedList;
public class FileList {
private List filePool = null;
private static FileList instance = null;
private FileList() {
filePool = new LinkedList();
}
public synchronized static void create() {
if(instance == null)
instance = new FileList();
}
public static FileList getInstance() {
if(instance == null)
throw new NullPointerException("FileList is null");
return instance;
}
public void addFile(SendFile fileName) {
synchronized(filePool) {
filePool.add(filePool.size(),fileName);
filePool.notifyAll();
}
}
public SendFile getFile() {
SendFile fileName = null;
synchronized(filePool) {
while(filePool.isEmpty()) {
try{
filePool.wait();
} catch(InterruptedException e) { }
}
fileName = (SendFile)filePool.remove(0);
}
return fileName;
}
}
class SendFile {
String fileName;
int flag;
public SendFile(String f,int g) {
fileName = f;
flag = g;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?