下面的java多线程程序中,设置断点的地方调试的时候只能断两三次,也就是断点只对这两三个线程起作用,怎么回事?
public static void main(String[] args) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
HashSet<String> s = new HashSet<>();
List<Integer> l = new ArrayList<>();
final String id = "x12323";
final String className = s.getClass().toString();
for(int j = 0; j<20; j++) {
fixedThreadPool.execute(() -> {
System.out.println("运行线程: " + Thread.currentThread().getName());
String lockObj = className + id;
synchronized (lockObj) { // 这里设置断点
if (s.isEmpty()) {
你是根据控制台输出来确定当前线程吗?
要看这个的:
因为多线程下,可能线程1 执行到
Sysout
,但是下一次就是线程2在访问synchweqronized
了。