如果其中一个线程失败了!那第二次会不会因为资源被占用以后都无法复制,或者因为线程一直等待或者死锁!
另外除了上面的问题.我写的有没有什么其他问题啊?????
public class cpFils { public boolean push() {
boolean reValue = false; try {
String[] toDirs = { "dir1", "dir2", "dir3" };
cpStruct tmpCps = new cpStruct();
for (String _dir : toDirs) {
tmpCps = new cpStruct();
tmpCps.setToDir(_dir);
new Thread(new ThreadCp(tmpCps)).start();
}
} catch (Exception e) {
// log
}
return reValue;
} public static void main(String arg[]) { new cpFils().push();
System.out.println("end");
}
}class ThreadCp implements Runnable {
public cpStruct cps; public ThreadCp() {
} public ThreadCp(cpStruct _cps) {
this.cps = _cps;
} public void run() {
try { String cpCmd = "copy " + cps.getCpFiles()[0] + " " + cps.getToDir();
Runtime.getRuntime().exec(" cmd /c " + cpCmd);
} catch (Exception e) {
// log
}
}}class cpStruct {
// 待Copy文件列表(目录+文件)
private final String[] cpFiles = { "path/file1", "path/file2" }; // Copy到的目标路径
private String toDir; public String[] getCpFiles() {
return cpFiles;
} public String getToDir() {
return toDir;
} public void setToDir(String toDir) {
this.toDir = toDir;
}
}
另外除了上面的问题.我写的有没有什么其他问题啊?????
public class cpFils { public boolean push() {
boolean reValue = false; try {
String[] toDirs = { "dir1", "dir2", "dir3" };
cpStruct tmpCps = new cpStruct();
for (String _dir : toDirs) {
tmpCps = new cpStruct();
tmpCps.setToDir(_dir);
new Thread(new ThreadCp(tmpCps)).start();
}
} catch (Exception e) {
// log
}
return reValue;
} public static void main(String arg[]) { new cpFils().push();
System.out.println("end");
}
}class ThreadCp implements Runnable {
public cpStruct cps; public ThreadCp() {
} public ThreadCp(cpStruct _cps) {
this.cps = _cps;
} public void run() {
try { String cpCmd = "copy " + cps.getCpFiles()[0] + " " + cps.getToDir();
Runtime.getRuntime().exec(" cmd /c " + cpCmd);
} catch (Exception e) {
// log
}
}}class cpStruct {
// 待Copy文件列表(目录+文件)
private final String[] cpFiles = { "path/file1", "path/file2" }; // Copy到的目标路径
private String toDir; public String[] getCpFiles() {
return cpFiles;
} public String getToDir() {
return toDir;
} public void setToDir(String toDir) {
this.toDir = toDir;
}
}
加只读锁,那线程失败...僵死..文件一直都只读.....5分钟后另外一个线程又copy的这个文件得时候由于有只读
锁所以无法覆盖............会吗?
加只读锁,那线程失败...僵死..文件一直都只读.....5分钟后另外一个线程又copy的这个文件得时候由于有只读
锁所以无法覆盖............会吗?--------------------------------------------------------------------------------------------
这种情况不是很容易测试出来!现在先想知道理论上是否有这种可能?