#vulnerable code 
                             public void threadDumpIfNeed(String reasonMsg) {
		if (!enable) {
			return;
		}

		synchronized (this) {
			if (System.currentTimeMillis() - lastThreadDumpTime < leastIntervalMills) {
				return;
			} else {
				lastThreadDumpTime = System.currentTimeMillis();
			}
		}

		logger.info("Thread dump by ThreadDumpper" + reasonMsg != null ? (" for " + reasonMsg) : "");

		// 参数均为false, 避免输出lockedMonitors和lockedSynchronizers导致的JVM缓慢
		ThreadInfo[] threadInfos = threadMBean.dumpAllThreads(false, false);

		StringBuilder b = new StringBuilder(8192);
		b.append('[');
		for (int i = 0; i < threadInfos.length; i++) {
			b.append(dumpThreadInfo(threadInfos[i])).append(", ");
		}

		// 两条日志间的时间间隔，是VM被thread dump堵塞的时间.
		logger.info(b.toString());
	} 
                            #location 2 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                             public void threadDumpIfNeed(String reasonMsg) {
		if (!enable) {
			return;
		}

		synchronized (this) {
			if (System.currentTimeMillis() - lastThreadDumpTime < leastIntervalMills) {
				return;
			} else {
				lastThreadDumpTime = System.currentTimeMillis();
			}
		}

		logger.info("Thread dump by ThreadDumpper" + (reasonMsg != null ? (" for " + reasonMsg) : ""));

		Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces();
		// 两条日志间的时间间隔，是VM被thread dump堵塞的时间.
		logger.info("Finish the threads snapshot");

		StringBuilder sb = new StringBuilder(8192 * 20).append("\n");

		for (Entry<Thread, StackTraceElement[]> entry : threads.entrySet()) {
			dumpThreadInfo(entry.getKey(), entry.getValue(), sb);
		}
		logger.info(sb.toString());

	}