Test.java
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.sitech.ismp.check.mbean;
import com.sitech.util.Formater;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
public class Test implements Runnable {
String name;
public Test(String name){
this.name = name;
}
public Test(){}
@Override
public void run() {
System.out.println(this.getClass().getResource("/"));
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println(ClassLoader.getSystemResource(""));
File cacheDataDir = new File("../cache/data/"+ Formater.getToday());
System.out.println("check dir exist!!");
if(!cacheDataDir.exists()){
System.out.println("dir not exist");
cacheDataDir.mkdirs();
System.out.println("make dir");
}
File cacheTempDir = new File("../cache/temp/"+ Formater.getToday());
System.out.println("check temp dir exist");
if(!cacheTempDir.exists()){
System.out.println("dir temp not exist");
cacheTempDir.mkdirs();
}
if(cacheDataDir.exists() && cacheTempDir.exists()){
System.out.println("begin write data to file!!");
FileWriter writer = null;
try {
String path = cacheTempDir.getPath()+"/testfile";
System.out.println(path);
writer = new FileWriter(new File(path));
for (int i = 0; i < 100; i++) {
System.out.print(name + i + "\r\n");
writer.write(name + i + "\r\n");
Thread.sleep(200);
}
}catch (Exception ex){
ex.printStackTrace();
}finally {
if(writer != null){
try {
writer.flush();
writer.close();
}catch (Exception ex){writer = null;}
}
}
}
}
public String test(String str) {
System.out.println(str);
return "SUCCESS";
}
public static void main(String args[]) throws Exception{
new Thread(new Test("thread-1 ")).start();
new Thread(new Test("thread-2 ")).start();
new Thread(new Test("thread-3 ")).start();
}
}