多线程写不同的file

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();
			} 


		}
	}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值