crossoverJie / crossoverJie/JCSprout
交替打印奇偶数,控制输出到1000,但是经过测试发现有时会输出到1001
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
[代码地址](https://github.com/crossoverJie/JCSprout/blob/master/src/main/java/com/crossoverjie/actual/TwoThread.java)
**运行结果**:

**分析**
1、当奇数线程在箭头处发生上下文切换
2、偶数线程获取锁,输出1000,并将number.start加为1001,释放锁,判断1001>1000,线程结束
3、奇数线程恢复执行,就会输出1001

Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/main/java/com/crossoverjie/actual/TwoThread.java and reproduce the alternating-thread output repeatedly. Inspect the synchronization around the number limit and verify that the program never prints a value above 1000; done means the observed race is eliminated without breaking alternating output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100