public class SessionRunnable implements Runnable {
public static void main(String[] args) {
Runnable runnable = new SessionRunnable();
Thread thread1 = new Thread(runnable);
Thread thread2 = new Thread(runnable);
Thread thread3 = new Thread(runnable);
Thread thread4 = new Thread(runnable);
Thread thread5 = new Thread(runnable);
Thread thread6 = new Thread(runnable);
Thread thread7 = new Thread(runnable);
Thread thread8 = new Thread(runnable);
Thread thread9 = new Thread(runnable);
Thread thread10 = new Thread(runnable);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
thread6.start();
thread7.start();
thread8.start();
thread9.start();
thread10.start();
}
@Override
public void run() {
long id = Thread.currentThread().getId();
int ThreadId = (int) (id - 8);
Map<String, String> params = new HashMap<String, String>();
params.put("userName", "sbry");
params.put("userPwd", "1");
String url0 = "http://192.168.3.150/SHBZ/mlogcheck";
String post0 = "";
try {
post0 = OkHttpUtil.Post(url0, params, ThreadId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(post0);
for (int i = 0; i < 10000000; i++) {
Map<String, String> map = new HashMap<>();
map.put("userId", "sbry");
map.put("rows", String.valueOf("1"));
map.put("page", String.valueOf("1"));
String url = "http://192.168.3.150/SHBZ/do/control/InsurerDo/mobileListTest";
String post = "";
try {
post = OkHttpUtil.Post(url, map, ThreadId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sessionInfo = post.substring(23) + "+++ThreadID:" + ThreadId;
System.out.println(sessionInfo);
FileWriter fw;
try {
fw = new FileWriter("d:\\log\\" + ThreadId + "out.txt",true);
PrintWriter out = new PrintWriter(fw);
out.println(sessionInfo);
out.flush();
out.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
多线程写不同的file
最新推荐文章于 2021-05-04 10:28:32 发布