设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序。
Design 4 threads: two threads increment j by 1 each time, and the other two decrement j by 1 each time. Write the program.
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: medium
分类: Concurrency, Java
标签: Thread, synchronized, Runnable
参考答案摘要
答案 以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题。 package com.sxy; /** * * @author sunxy */ public class TestDemo { private int j; public static void main(String args[]) { TestDemo tt = new TestDemo(); Inc inc = tt.n...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。