课题打卡~请老师检查
package com.imooc.thread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ThreadLocalStringBuilder { private static ExecutorService executorService = Executors.newFixedThreadPool(10); public String data(int num) { StringBuilder stringBuilder = ThreadSafeStringBuilder.stringBuilderThreadLocal.get(); stringBuilder.setLength(0); stringBuilder.append("数字"+num); return stringBuilder.toString(); } public static void main(String[] args) { StringBuilder val = new StringBuilder(); for (int i = 1; i <= 20; i++) { int finalI = i; executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(1); String data = new ThreadLocalStringBuilder().data(finalI); System.out.println(data); } catch (InterruptedException e) { e.printStackTrace(); } } }); } executorService.shutdown(); } }
32
收起
正在回答
3回答
同学你好,测试同学的代码是可以的,棒棒的,建议同学下次按照作业需求将代码提交完整
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
java工程师2020版
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星