| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:多线程的运行令人费解
取消只看楼主 加入收藏
康之恋
Rank: 2
来 自:梅州
等 级:论坛游民
帖 子:43
专家分:20
注 册:2009-4-18
结帖率:100%
收藏
 问题点数:0 回复次数:3 
多线程的运行令人费解
public class Ex8_6{
    public static void main(String[] args){
        SellTickets t1=new SellTickets();  
SellTickets t2=new SellTickets();
SellTickets t3=new SellTickets();  
       new Thread(t1).start();      
        new Thread(t2).start();
        new Thread(t3).start();
    }
}
class SellTickets implements Runnable
{
    private int tickets=200;   
    public void run()
    {
        while(tickets>0)
         {
          System.out.println( Thread.currentThread().getName() +
                                            " is selling ticket "+tickets--);
       }
    }
}
为什么运行结果不是三个线程各自售票200??而出现了一些让人摸不着头脑的数字!请各位高手为新手解答下!无尽感激
搜索更多相关主题的帖子: 线程 运行 
2009-09-16 13:46
康之恋
Rank: 2
来 自:梅州
等 级:论坛游民
帖 子:43
专家分:20
注 册:2009-4-18
收藏
得分:0 
线程本来是从200开始减下来!但我的第一个线程执行时出现的数字却是105!我觉得这些数字让我摸不着头脑,而且在结果中根本就见不到大于105的数字

[ 本帖最后由 康之恋 于 2009-9-16 18:02 编辑 ]

我是编程新手,希望能和各位共同学习
2009-09-16 18:01
康之恋
Rank: 2
来 自:梅州
等 级:论坛游民
帖 子:43
专家分:20
注 册:2009-4-18
收藏
得分:0 
Thread-1 is selling ticket 118
Thread-1 is selling ticket 117
Thread-0 is selling ticket 94
Thread-0 is selling ticket 93
Thread-0 is selling ticket 92
Thread-0 is selling ticket 91
Thread-0 is selling ticket 90
Thread-0 is selling ticket 89
Thread-0 is selling ticket 88
Thread-0 is selling ticket 87
Thread-2 is selling ticket 86
Thread-2 is selling ticket 85
Thread-2 is selling ticket 84
Thread-2 is selling ticket 83
Thread-2 is selling ticket 82
Thread-2 is selling ticket 81
Thread-2 is selling ticket 80
Thread-2 is selling ticket 79
Thread-1 is selling ticket 116
Thread-1 is selling ticket 115
Thread-1 is selling ticket 114
Thread-1 is selling ticket 113
Thread-1 is selling ticket 112
Thread-1 is selling ticket 111
Thread-1 is selling ticket 110
Thread-1 is selling ticket 109
Thread-0 is selling ticket 86
Thread-0 is selling ticket 85
Thread-0 is selling ticket 84
Thread-0 is selling ticket 83
Thread-0 is selling ticket 82
Thread-0 is selling ticket 81
Thread-0 is selling ticket 80
Thread-0 is selling ticket 79
Thread-2 is selling ticket 78
Thread-2 is selling ticket 77
Thread-2 is selling ticket 76
Thread-2 is selling ticket 75
Thread-2 is selling ticket 74
Thread-2 is selling ticket 73
Thread-2 is selling ticket 72
Thread-2 is selling ticket 71
Thread-1 is selling ticket 108
Thread-1 is selling ticket 107
Thread-1 is selling ticket 106
Thread-1 is selling ticket 105
Thread-1 is selling ticket 104
Thread-1 is selling ticket 103
Thread-1 is selling ticket 102
Thread-1 is selling ticket 101
Thread-0 is selling ticket 78
Thread-0 is selling ticket 77
Thread-0 is selling ticket 76
Thread-0 is selling ticket 75
Thread-0 is selling ticket 74
Thread-0 is selling ticket 73
Thread-0 is selling ticket 72
Thread-0 is selling ticket 71
Thread-2 is selling ticket 70
Thread-2 is selling ticket 69
Thread-2 is selling ticket 68
Thread-2 is selling ticket 67
Thread-2 is selling ticket 66
Thread-2 is selling ticket 65
Thread-2 is selling ticket 64
Thread-2 is selling ticket 63
Thread-1 is selling ticket 100
Thread-1 is selling ticket 99
Thread-1 is selling ticket 98
Thread-1 is selling ticket 97
Thread-1 is selling ticket 96
Thread-1 is selling ticket 95
Thread-1 is selling ticket 94
Thread-1 is selling ticket 93
Thread-0 is selling ticket 70
Thread-0 is selling ticket 69
Thread-0 is selling ticket 68
Thread-0 is selling ticket 67
Thread-0 is selling ticket 66
Thread-0 is selling ticket 65
Thread-0 is selling ticket 64
Thread-0 is selling ticket 63
Thread-2 is selling ticket 62
Thread-2 is selling ticket 61
Thread-2 is selling ticket 60
Thread-2 is selling ticket 59
Thread-2 is selling ticket 58
Thread-2 is selling ticket 57
Thread-2 is selling ticket 56
Thread-2 is selling ticket 55
Thread-1 is selling ticket 92
Thread-1 is selling ticket 91
Thread-1 is selling ticket 90
Thread-1 is selling ticket 89
Thread-1 is selling ticket 88
Thread-1 is selling ticket 87
Thread-0 is selling ticket 62
Thread-0 is selling ticket 61
Thread-0 is selling ticket 60
Thread-0 is selling ticket 59
Thread-0 is selling ticket 58
Thread-0 is selling ticket 57
Thread-0 is selling ticket 56
Thread-0 is selling ticket 55
Thread-2 is selling ticket 54
Thread-2 is selling ticket 53
Thread-2 is selling ticket 52
Thread-2 is selling ticket 51
Thread-2 is selling ticket 50
Thread-2 is selling ticket 49
Thread-2 is selling ticket 48
Thread-2 is selling ticket 47
Thread-1 is selling ticket 86
Thread-1 is selling ticket 85
Thread-1 is selling ticket 84
Thread-1 is selling ticket 83
Thread-1 is selling ticket 82
Thread-1 is selling ticket 81
Thread-1 is selling ticket 80
Thread-1 is selling ticket 79
Thread-0 is selling ticket 54
Thread-0 is selling ticket 53
Thread-0 is selling ticket 52
Thread-0 is selling ticket 51
Thread-0 is selling ticket 50
Thread-0 is selling ticket 49
Thread-0 is selling ticket 48
Thread-0 is selling ticket 47
Thread-2 is selling ticket 46
Thread-2 is selling ticket 45
Thread-2 is selling ticket 44
Thread-2 is selling ticket 43
Thread-2 is selling ticket 42
Thread-2 is selling ticket 41
Thread-2 is selling ticket 40
Thread-2 is selling ticket 39
Thread-1 is selling ticket 78
Thread-1 is selling ticket 77
Thread-1 is selling ticket 76
Thread-1 is selling ticket 75
Thread-1 is selling ticket 74
Thread-1 is selling ticket 73
Thread-1 is selling ticket 72
Thread-1 is selling ticket 71
Thread-0 is selling ticket 46
Thread-0 is selling ticket 45
Thread-0 is selling ticket 44
Thread-0 is selling ticket 43
Thread-0 is selling ticket 42
Thread-0 is selling ticket 41
Thread-0 is selling ticket 40
Thread-0 is selling ticket 39
Thread-2 is selling ticket 38
Thread-2 is selling ticket 37
Thread-2 is selling ticket 36
Thread-2 is selling ticket 35
Thread-2 is selling ticket 34
Thread-2 is selling ticket 33
Thread-2 is selling ticket 32
Thread-2 is selling ticket 31
Thread-1 is selling ticket 70
Thread-1 is selling ticket 69
Thread-1 is selling ticket 68
Thread-1 is selling ticket 67
Thread-1 is selling ticket 66
Thread-1 is selling ticket 65
Thread-1 is selling ticket 64
Thread-1 is selling ticket 63
Thread-0 is selling ticket 38
Thread-0 is selling ticket 37
Thread-0 is selling ticket 36
Thread-0 is selling ticket 35
Thread-0 is selling ticket 34
Thread-0 is selling ticket 33
Thread-0 is selling ticket 32
Thread-0 is selling ticket 31
Thread-2 is selling ticket 30
Thread-2 is selling ticket 29
Thread-2 is selling ticket 28
Thread-2 is selling ticket 27
Thread-2 is selling ticket 26
Thread-2 is selling ticket 25
Thread-2 is selling ticket 24
Thread-2 is selling ticket 23
Thread-1 is selling ticket 62
Thread-1 is selling ticket 61
Thread-1 is selling ticket 60
Thread-1 is selling ticket 59
Thread-1 is selling ticket 58
Thread-1 is selling ticket 57
Thread-1 is selling ticket 56
Thread-1 is selling ticket 55
Thread-0 is selling ticket 30
Thread-0 is selling ticket 29
Thread-0 is selling ticket 28
Thread-0 is selling ticket 27
Thread-0 is selling ticket 26
Thread-0 is selling ticket 25
Thread-0 is selling ticket 24
Thread-0 is selling ticket 23
Thread-2 is selling ticket 22
Thread-2 is selling ticket 21
Thread-2 is selling ticket 20
Thread-2 is selling ticket 19
Thread-2 is selling ticket 18
Thread-2 is selling ticket 17
Thread-2 is selling ticket 16
Thread-2 is selling ticket 15
Thread-1 is selling ticket 54
Thread-1 is selling ticket 53
Thread-1 is selling ticket 52
Thread-1 is selling ticket 51
Thread-1 is selling ticket 50
Thread-1 is selling ticket 49
Thread-1 is selling ticket 48
Thread-1 is selling ticket 47
Thread-0 is selling ticket 22
Thread-0 is selling ticket 21
Thread-0 is selling ticket 20
Thread-0 is selling ticket 19
Thread-0 is selling ticket 18
Thread-0 is selling ticket 17
Thread-0 is selling ticket 16
Thread-0 is selling ticket 15
Thread-2 is selling ticket 14
Thread-2 is selling ticket 13
Thread-2 is selling ticket 12
Thread-2 is selling ticket 11
Thread-2 is selling ticket 10
Thread-2 is selling ticket 9
Thread-2 is selling ticket 8
Thread-2 is selling ticket 7
Thread-1 is selling ticket 46
Thread-1 is selling ticket 45
Thread-1 is selling ticket 44
Thread-1 is selling ticket 43
Thread-1 is selling ticket 42
Thread-1 is selling ticket 41
Thread-1 is selling ticket 40
Thread-1 is selling ticket 39
Thread-0 is selling ticket 14
Thread-0 is selling ticket 13
Thread-0 is selling ticket 12
Thread-0 is selling ticket 11
Thread-0 is selling ticket 10
Thread-0 is selling ticket 9
Thread-0 is selling ticket 8
Thread-0 is selling ticket 7
Thread-2 is selling ticket 6
Thread-2 is selling ticket 5
Thread-2 is selling ticket 4
Thread-2 is selling ticket 3
Thread-2 is selling ticket 2
Thread-2 is selling ticket 1
Thread-1 is selling ticket 38
Thread-1 is selling ticket 37
Thread-1 is selling ticket 36
Thread-1 is selling ticket 35
Thread-1 is selling ticket 34
Thread-1 is selling ticket 33
Thread-1 is selling ticket 32
Thread-1 is selling ticket 31
Thread-1 is selling ticket 30
Thread-0 is selling ticket 6
Thread-0 is selling ticket 5
Thread-0 is selling ticket 4
Thread-0 is selling ticket 3
Thread-0 is selling ticket 2
Thread-0 is selling ticket 1
Thread-1 is selling ticket 29
Thread-1 is selling ticket 28
Thread-1 is selling ticket 27
Thread-1 is selling ticket 26
Thread-1 is selling ticket 25
Thread-1 is selling ticket 24
Thread-1 is selling ticket 23
Thread-1 is selling ticket 22
Thread-1 is selling ticket 21
Thread-1 is selling ticket 20
Thread-1 is selling ticket 19
Thread-1 is selling ticket 18
Thread-1 is selling ticket 17
Thread-1 is selling ticket 16
Thread-1 is selling ticket 15
Thread-1 is selling ticket 14
Thread-1 is selling ticket 13
Thread-1 is selling ticket 12
Thread-1 is selling ticket 11
Thread-1 is selling ticket 10
Thread-1 is selling ticket 9
Thread-1 is selling ticket 8
Thread-1 is selling ticket 7
Thread-1 is selling ticket 6
Thread-1 is selling ticket 5
Thread-1 is selling ticket 4
Thread-1 is selling ticket 3
Thread-1 is selling ticket 2
Thread-1 is selling ticket 1
 
这是我本机上运行的结果?根本原因在那?有哪位大侠能说说

我是编程新手,希望能和各位共同学习
2009-09-16 22:34
康之恋
Rank: 2
来 自:梅州
等 级:论坛游民
帖 子:43
专家分:20
注 册:2009-4-18
收藏
得分:0 
回复 7楼 我爱JAVA1
谢谢诸位的解答

我是编程新手,希望能和各位共同学习
2009-09-18 15:20
快速回复:多线程的运行令人费解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031530 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved