centos上安装autoconf-2.69
2013-12-28 10:33
381 查看
package com; public class TraditionalThreadSynchronizeTest { public static void main(String[] args) { new TraditionalThreadSynchronizeTest().init(); } public void init() { final Output output = new Output(); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } output.output("zhangxiaoxiang"); } } }).start(); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } output.output2("lihuoming"); } } }) .start(); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } output.output3("lihuoming"); } } }) .start(); } static class Output { public void output(String name) { int len = name.length(); synchronized (Output.class) { //synchronized (this) { for (int i = 0; i < len; i++) { System.out.print(name.charAt(i)); } System.out.println(); } } public synchronized void output2(String name) { int len = name.length(); // synchronized (Output.class) { //synchronized (this) { for (int i = 0; i < len; i++) { System.out.print(name.charAt(i)); //} System.out.println(); } } public static synchronized void output3(String name) { int len = name.length(); // synchronized (Output.class) { //synchronized (this) { for (int i = 0; i < len; i++) { System.out.print(name.charAt(i)); //} System.out.println(); } } } }
本文出自 “狐灵传说” 博客,请务必保留此出处http://foxspark.blog.51cto.com/6273668/1275847
相关文章推荐
- linux驱动开发--字符设备:创建一组设备节点
- linux驱动开发--字符设备:自动创建设备节点
- Linux 进程状态
- GIT在Linux上的安装和使用简介
- linux下find查找命令用法
- 我为什么要学习Linux?
- CentOS安装KVM虚拟化(firadio-supermicro)
- Linux新手之路 - fdisk mke2fs mount
- s3c6410 完全由SD卡启动Linux流程
- [Linux]linux mount命令-o参数sync选项的用法
- (转载)Ubuntu Server 12.04 安装教程
- centos6.3安装zabbix2.0.2记录
- CentOS安装JDK1.7
- linux文件系统的创建和挂载
- 在Windows Azure上基于CentOS 6.3部署MySQL 5.6主从式数据库(2)
- Linux下C语言执行MySQL语句
- 关于Linux字符集的查看及修改
- CentOS源代码ftp的安装
- 永远不要在Linux执行的10个最危险的命令
- Linux下检测网卡与网线的连接状态