package 经典;

public class 四个线程 {

    private int j=10;

    /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub 四个线程 mainClass=new 四个线程(); for(int i=2; i>0; i--)
{
Thread thread=new Thread(mainClass.new IncThread());
thread.start();
thread=new Thread(mainClass.new DecThread());
thread.start();
} } private synchronized void inc(){
j++;
System.out.println(Thread.currentThread().getName()+", j="+j);
} private synchronized void dec(){
j--;
System.out.println(Thread.currentThread().getName()+", j="+j);
} class IncThread implements Runnable{ @Override
public void run() {
// TODO Auto-generated method stub
for(int i=20; i>0 ;i--)
inc();
} } class DecThread implements Runnable{ @Override
public void run() {
// TODO Auto-generated method stub
for(int i=20; i>0 ;i--)
dec();
}
} }

最新文章

  1. hdu2302(枚举,大数取模)
  2. mac与php环境
  3. mysql完整备份时过滤掉某些库
  4. AtomicInteger源码分析
  5. SQL基础教程
  6. c++中的243、251、250错误原因
  7. 个推推送Android问题检测
  8. C#_deepCopy
  9. Portal相关技术及架构
  10. POJ 1845 Sumdiv(因子分解+快速幂+二分求和)
  11. 大型分布式C++框架《二:大包处理过程》
  12. js实现页面重定位的几种方法
  13. 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用
  14. Mac上安装openCV(Java版本)
  15. CCF-CIDR合并-201812-3
  16. js实现复制内容到粘贴板
  17. SpringMVC中的一些注解
  18. 磁盘测试工具FIO工具安装和使用方法
  19. 1.0 poi单元格合合并及写入
  20. Qt 常用类 (4)—— QPoint

热门文章

  1. 【转】Linux下编译ffmpeg
  2. js相对定位
  3. UITextView 输入长度限制
  4. wifi_uplink脚本分析
  5. C#调用WebService实例和开发
  6. struts2 404处理
  7. c++设计模式之状态模式
  8. 第一章 Qt入门
  9. Dx 1 error; aborting Conversion to Dalvik format failed with error 1
  10. 字符串分割与数组的分割 split()VSsplice()&slice()