多线程的运行令人费解
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??而出现了一些让人摸不着头脑的数字!请各位高手为新手解答下!无尽感激
----------------解决方案--------------------------------------------------------
楼主,你的程序看不出有什么问题,你说的摸不着头脑的数字是什么?
----------------解决方案--------------------------------------------------------
线程本来是从200开始减下来!但我的第一个线程执行时出现的数字却是105!我觉得这些数字让我摸不着头脑,而且在结果中根本就见不到大于105的数字
[ 本帖最后由 康之恋 于 2009-9-16 18:02 编辑 ]
----------------解决方案--------------------------------------------------------
这是我的运行结果,没发现你说的那情况.
3个线程都是从200自减到1就结束
Thread-0 is selling ticket 200
Thread-0 is selling ticket 199
Thread-0 is selling ticket 198
Thread-0 is selling ticket 197
Thread-0 is selling ticket 196
Thread-0 is selling ticket 195
Thread-0 is selling ticket 194
Thread-0 is selling ticket 193
Thread-0 is selling ticket 192
Thread-0 is selling ticket 191
Thread-0 is selling ticket 190
Thread-0 is selling ticket 189
Thread-0 is selling ticket 188
Thread-0 is selling ticket 187
Thread-0 is selling ticket 186
Thread-0 is selling ticket 185
Thread-0 is selling ticket 184
Thread-1 is selling ticket 200
Thread-2 is selling ticket 200
Thread-0 is selling ticket 183
Thread-1 is selling ticket 199
Thread-2 is selling ticket 199
Thread-0 is selling ticket 182
Thread-1 is selling ticket 198
Thread-2 is selling ticket 198
Thread-0 is selling ticket 181
Thread-1 is selling ticket 197
Thread-2 is selling ticket 197
Thread-0 is selling ticket 180
Thread-1 is selling ticket 196
Thread-2 is selling ticket 196
Thread-0 is selling ticket 179
Thread-1 is selling ticket 195
Thread-0 is selling ticket 178
Thread-1 is selling ticket 194
Thread-0 is selling ticket 177
Thread-1 is selling ticket 193
Thread-0 is selling ticket 176
Thread-1 is selling ticket 192
Thread-0 is selling ticket 175
Thread-0 is selling ticket 174
Thread-0 is selling ticket 173
Thread-0 is selling ticket 172
Thread-0 is selling ticket 171
Thread-0 is selling ticket 170
Thread-2 is selling ticket 195
Thread-1 is selling ticket 191
Thread-2 is selling ticket 194
Thread-1 is selling ticket 190
Thread-2 is selling ticket 193
Thread-1 is selling ticket 189
Thread-2 is selling ticket 192
Thread-1 is selling ticket 188
Thread-2 is selling ticket 191
Thread-0 is selling ticket 169
Thread-2 is selling ticket 190
Thread-0 is selling ticket 168
Thread-1 is selling ticket 187
Thread-0 is selling ticket 167
Thread-1 is selling ticket 186
Thread-0 is selling ticket 166
Thread-1 is selling ticket 185
Thread-0 is selling ticket 165
Thread-2 is selling ticket 189
Thread-1 is selling ticket 184
Thread-2 is selling ticket 188
Thread-1 is selling ticket 183
Thread-2 is selling ticket 187
Thread-0 is selling ticket 164
Thread-2 is selling ticket 186
Thread-0 is selling ticket 163
Thread-2 is selling ticket 185
Thread-0 is selling ticket 162
Thread-2 is selling ticket 184
Thread-0 is selling ticket 161
Thread-1 is selling ticket 182
Thread-0 is selling ticket 160
Thread-1 is selling ticket 181
Thread-0 is selling ticket 159
Thread-2 is selling ticket 183
Thread-1 is selling ticket 180
Thread-2 is selling ticket 182
Thread-1 is selling ticket 179
Thread-2 is selling ticket 181
Thread-1 is selling ticket 178
Thread-2 is selling ticket 180
Thread-0 is selling ticket 158
Thread-2 is selling ticket 179
Thread-0 is selling ticket 157
Thread-2 is selling ticket 178
Thread-0 is selling ticket 156
Thread-1 is selling ticket 177
Thread-0 is selling ticket 155
Thread-1 is selling ticket 176
Thread-0 is selling ticket 154
Thread-1 is selling ticket 175
Thread-2 is selling ticket 177
Thread-1 is selling ticket 174
Thread-2 is selling ticket 176
Thread-1 is selling ticket 173
Thread-2 is selling ticket 175
Thread-1 is selling ticket 172
Thread-2 is selling ticket 174
Thread-0 is selling ticket 153
Thread-2 is selling ticket 173
Thread-0 is selling ticket 152
Thread-2 is selling ticket 172
Thread-0 is selling ticket 151
Thread-1 is selling ticket 171
Thread-0 is selling ticket 150
Thread-2 is selling ticket 171
Thread-0 is selling ticket 149
Thread-1 is selling ticket 170
Thread-2 is selling ticket 170
Thread-0 is selling ticket 148
Thread-1 is selling ticket 169
Thread-2 is selling ticket 169
Thread-1 is selling ticket 168
Thread-2 is selling ticket 168
Thread-1 is selling ticket 167
Thread-2 is selling ticket 167
Thread-1 is selling ticket 166
Thread-0 is selling ticket 147
Thread-1 is selling ticket 165
Thread-0 is selling ticket 146
Thread-2 is selling ticket 166
Thread-0 is selling ticket 145
Thread-2 is selling ticket 165
Thread-0 is selling ticket 144
Thread-1 is selling ticket 164
Thread-2 is selling ticket 164
Thread-0 is selling ticket 143
Thread-1 is selling ticket 163
Thread-2 is selling ticket 163
Thread-0 is selling ticket 142
Thread-1 is selling ticket 162
Thread-2 is selling ticket 162
Thread-1 is selling ticket 161
Thread-0 is selling ticket 141
Thread-1 is selling ticket 160
Thread-0 is selling ticket 140
Thread-1 is selling ticket 159
Thread-0 is selling ticket 139
Thread-2 is selling ticket 161
Thread-0 is selling ticket 138
Thread-1 is selling ticket 158
Thread-2 is selling ticket 160
Thread-0 is selling ticket 137
Thread-1 is selling ticket 157
Thread-0 is selling ticket 136
Thread-1 is selling ticket 156
Thread-2 is selling ticket 159
Thread-1 is selling ticket 155
Thread-2 is selling ticket 158
Thread-1 is selling ticket 154
Thread-2 is selling ticket 157
Thread-1 is selling ticket 153
Thread-2 is selling ticket 156
Thread-0 is selling ticket 135
Thread-2 is selling ticket 155
Thread-0 is selling ticket 134
Thread-2 is selling ticket 154
Thread-1 is selling ticket 152
Thread-0 is selling ticket 133
Thread-1 is selling ticket 151
Thread-1 is selling ticket 150
Thread-1 is selling ticket 149
Thread-1 is selling ticket 148
Thread-1 is selling ticket 147
Thread-1 is selling ticket 146
Thread-1 is selling ticket 145
Thread-1 is selling ticket 144
Thread-1 is selling ticket 143
Thread-1 is selling ticket 142
Thread-1 is selling ticket 141
Thread-1 is selling ticket 140
Thread-1 is selling ticket 139
Thread-0 is selling ticket 132
Thread-2 is selling ticket 153
Thread-1 is selling ticket 138
Thread-0 is selling ticket 131
Thread-2 is selling ticket 152
Thread-1 is selling ticket 137
Thread-0 is selling ticket 130
Thread-2 is selling ticket 151
Thread-1 is selling ticket 136
Thread-0 is selling ticket 129
Thread-2 is selling ticket 150
Thread-0 is selling ticket 128
Thread-2 is selling ticket 149
Thread-1 is selling ticket 135
Thread-2 is selling ticket 148
Thread-1 is selling ticket 134
Thread-0 is selling ticket 127
Thread-1 is selling ticket 133
Thread-2 is selling ticket 147
Thread-0 is selling ticket 126
Thread-1 is selling ticket 132
Thread-2 is selling ticket 146
Thread-0 is selling ticket 125
Thread-1 is selling ticket 131
Thread-2 is selling ticket 145
Thread-0 is selling ticket 124
Thread-1 is selling ticket 130
Thread-2 is selling ticket 144
Thread-0 is selling ticket 123
Thread-2 is selling ticket 143
Thread-1 is selling ticket 129
Thread-2 is selling ticket 142
Thread-1 is selling ticket 128
Thread-0 is selling ticket 122
Thread-2 is selling ticket 141
Thread-1 is selling ticket 127
Thread-0 is selling ticket 121
Thread-2 is selling ticket 140
Thread-1 is selling ticket 126
Thread-0 is selling ticket 120
Thread-2 is selling ticket 139
Thread-1 is selling ticket 125
Thread-0 is selling ticket 119
Thread-2 is selling ticket 138
Thread-0 is selling ticket 118
Thread-2 is selling ticket 137
Thread-0 is selling ticket 117
Thread-2 is selling ticket 136
Thread-1 is selling ticket 124
Thread-0 is selling ticket 116
Thread-1 is selling ticket 123
Thread-2 is selling ticket 135
Thread-0 is selling ticket 115
Thread-1 is selling ticket 122
Thread-2 is selling ticket 134
Thread-0 is selling ticket 114
Thread-1 is selling ticket 121
Thread-2 is selling ticket 133
Thread-0 is selling ticket 113
Thread-1 is selling ticket 120
Thread-2 is selling ticket 132
Thread-0 is selling ticket 112
Thread-1 is selling ticket 119
Thread-2 is selling ticket 131
Thread-0 is selling ticket 111
Thread-2 is selling ticket 130
Thread-0 is selling ticket 110
Thread-1 is selling ticket 118
Thread-2 is selling ticket 129
Thread-0 is selling ticket 109
Thread-1 is selling ticket 117
Thread-0 is selling ticket 108
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-1 is selling ticket 108
Thread-1 is selling ticket 107
Thread-1 is selling ticket 106
Thread-0 is selling ticket 107
Thread-2 is selling ticket 128
Thread-1 is selling ticket 105
Thread-0 is selling ticket 106
Thread-2 is selling ticket 127
Thread-0 is selling ticket 105
Thread-2 is selling ticket 126
Thread-0 is selling ticket 104
Thread-2 is selling ticket 125
Thread-0 is selling ticket 103
Thread-2 is selling ticket 124
Thread-0 is selling ticket 102
Thread-2 is selling ticket 123
Thread-1 is selling ticket 104
Thread-0 is selling ticket 101
Thread-1 is selling ticket 103
Thread-0 is selling ticket 100
Thread-2 is selling ticket 122
Thread-1 is selling ticket 102
Thread-0 is selling ticket 99
Thread-2 is selling ticket 121
Thread-1 is selling ticket 101
Thread-0 is selling ticket 98
Thread-2 is selling ticket 120
Thread-1 is selling ticket 100
Thread-0 is selling ticket 97
Thread-2 is selling ticket 119
Thread-0 is selling ticket 96
Thread-2 is selling ticket 118
Thread-1 is selling ticket 99
Thread-2 is selling ticket 117
Thread-1 is selling ticket 98
Thread-0 is selling ticket 95
Thread-1 is selling ticket 97
Thread-2 is selling ticket 116
Thread-0 is selling ticket 94
Thread-1 is selling ticket 96
Thread-2 is selling ticket 115
Thread-0 is selling ticket 93
Thread-1 is selling ticket 95
Thread-2 is selling ticket 114
Thread-0 is selling ticket 92
Thread-1 is selling ticket 94
Thread-2 is selling ticket 113
Thread-0 is selling ticket 91
Thread-2 is selling ticket 112
Thread-1 is selling ticket 93
Thread-2 is selling ticket 111
Thread-1 is selling ticket 92
Thread-0 is selling ticket 90
Thread-1 is selling ticket 91
Thread-2 is selling ticket 110
Thread-0 is selling ticket 89
Thread-1 is selling ticket 90
Thread-2 is selling ticket 109
Thread-0 is selling ticket 88
Thread-1 is selling ticket 89
Thread-2 is selling ticket 108
Thread-0 is selling ticket 87
Thread-1 is selling ticket 88
Thread-2 is selling ticket 107
Thread-0 is selling ticket 86
Thread-2 is selling ticket 106
Thread-1 is selling ticket 87
Thread-2 is selling ticket 105
Thread-1 is selling ticket 86
Thread-0 is selling ticket 85
Thread-1 is selling ticket 85
Thread-2 is selling ticket 104
Thread-0 is selling ticket 84
Thread-1 is selling ticket 84
Thread-2 is selling ticket 103
Thread-1 is selling ticket 83
Thread-2 is selling ticket 102
Thread-1 is selling ticket 82
Thread-2 is selling ticket 101
Thread-0 is selling ticket 83
Thread-2 is selling ticket 100
Thread-0 is selling ticket 82
Thread-2 is selling ticket 99
Thread-0 is selling ticket 81
Thread-1 is selling ticket 81
Thread-0 is selling ticket 80
Thread-1 is selling ticket 80
Thread-0 is selling ticket 79
Thread-2 is selling ticket 98
Thread-1 is selling ticket 79
Thread-0 is selling ticket 78
Thread-2 is selling ticket 97
Thread-1 is selling ticket 78
Thread-2 is selling ticket 96
Thread-1 is selling ticket 77
Thread-2 is selling ticket 95
Thread-0 is selling ticket 77
Thread-2 is selling ticket 94
Thread-0 is selling ticket 76
Thread-2 is selling ticket 93
Thread-0 is selling ticket 75
Thread-1 is selling ticket 76
Thread-0 is selling ticket 74
Thread-1 is selling ticket 75
Thread-0 is selling ticket 73
Thread-2 is selling ticket 92
Thread-1 is selling ticket 74
Thread-0 is selling ticket 72
Thread-2 is selling ticket 91
Thread-1 is selling ticket 73
Thread-2 is selling ticket 90
Thread-1 is selling ticket 72
Thread-2 is selling ticket 89
Thread-0 is selling ticket 71
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-2 is selling ticket 88
Thread-1 is selling ticket 71
Thread-0 is selling ticket 63
Thread-2 is selling ticket 87
Thread-1 is selling ticket 70
Thread-0 is selling ticket 62
Thread-2 is selling ticket 86
Thread-1 is selling ticket 69
Thread-0 is selling ticket 61
Thread-2 is selling ticket 85
Thread-1 is selling ticket 68
Thread-0 is selling ticket 60
Thread-2 is selling ticket 84
Thread-1 is selling ticket 67
Thread-2 is selling ticket 83
Thread-1 is selling ticket 66
Thread-0 is selling ticket 59
Thread-2 is selling ticket 82
Thread-1 is selling ticket 65
Thread-0 is selling ticket 58
Thread-2 is selling ticket 81
Thread-1 is selling ticket 64
Thread-0 is selling ticket 57
Thread-2 is selling ticket 80
Thread-1 is selling ticket 63
Thread-0 is selling ticket 56
Thread-2 is selling ticket 79
Thread-1 is selling ticket 62
Thread-0 is selling ticket 55
Thread-2 is selling ticket 78
Thread-1 is selling ticket 61
Thread-2 is selling ticket 77
Thread-1 is selling ticket 60
Thread-0 is selling ticket 54
Thread-2 is selling ticket 76
Thread-1 is selling ticket 59
Thread-0 is selling ticket 53
Thread-2 is selling ticket 75
Thread-1 is selling ticket 58
Thread-0 is selling ticket 52
Thread-2 is selling ticket 74
Thread-1 is selling ticket 57
Thread-0 is selling ticket 51
Thread-2 is selling ticket 73
Thread-1 is selling ticket 56
Thread-0 is selling ticket 50
Thread-2 is selling ticket 72
Thread-1 is selling ticket 55
Thread-2 is selling ticket 71
Thread-1 is selling ticket 54
Thread-0 is selling ticket 49
Thread-2 is selling ticket 70
Thread-1 is selling ticket 53
Thread-0 is selling ticket 48
Thread-2 is selling ticket 69
Thread-1 is selling ticket 52
Thread-0 is selling ticket 47
Thread-2 is selling ticket 68
Thread-1 is selling ticket 51
Thread-0 is selling ticket 46
Thread-2 is selling ticket 67
Thread-1 is selling ticket 50
Thread-0 is selling ticket 45
Thread-2 is selling ticket 66
Thread-1 is selling ticket 49
Thread-2 is selling ticket 65
Thread-1 is selling ticket 48
Thread-0 is selling ticket 44
Thread-2 is selling ticket 64
Thread-1 is selling ticket 47
Thread-0 is selling ticket 43
Thread-2 is selling ticket 63
Thread-1 is selling ticket 46
Thread-0 is selling ticket 42
Thread-2 is selling ticket 62
Thread-1 is selling ticket 45
Thread-0 is selling ticket 41
Thread-2 is selling ticket 61
Thread-1 is selling ticket 44
Thread-0 is selling ticket 40
Thread-2 is selling ticket 60
Thread-1 is selling ticket 43
Thread-2 is selling ticket 59
Thread-1 is selling ticket 42
Thread-0 is selling ticket 39
Thread-2 is selling ticket 58
Thread-1 is selling ticket 41
Thread-0 is selling ticket 38
Thread-2 is selling ticket 57
Thread-1 is selling ticket 40
Thread-0 is selling ticket 37
Thread-2 is selling ticket 56
Thread-1 is selling ticket 39
Thread-0 is selling ticket 36
Thread-2 is selling ticket 55
Thread-1 is selling ticket 38
Thread-0 is selling ticket 35
Thread-2 is selling ticket 54
Thread-1 is selling ticket 37
Thread-2 is selling ticket 53
Thread-1 is selling ticket 36
Thread-0 is selling ticket 34
Thread-2 is selling ticket 52
Thread-1 is selling ticket 35
Thread-0 is selling ticket 33
Thread-2 is selling ticket 51
Thread-1 is selling ticket 34
Thread-2 is selling ticket 50
Thread-1 is selling ticket 33
Thread-0 is selling ticket 32
Thread-1 is selling ticket 32
Thread-0 is selling ticket 31
Thread-1 is selling ticket 31
Thread-0 is selling ticket 30
Thread-1 is selling ticket 30
Thread-0 is selling ticket 29
Thread-2 is selling ticket 49
Thread-0 is selling ticket 28
Thread-2 is selling ticket 48
Thread-0 is selling ticket 27
Thread-1 is selling ticket 29
Thread-2 is selling ticket 47
Thread-1 is selling ticket 28
Thread-2 is selling ticket 46
Thread-1 is selling ticket 27
Thread-2 is selling ticket 45
Thread-1 is selling ticket 26
Thread-0 is selling ticket 26
Thread-1 is selling ticket 25
Thread-0 is selling ticket 25
Thread-1 is selling ticket 24
Thread-0 is selling ticket 24
Thread-2 is selling ticket 44
Thread-0 is selling ticket 23
Thread-2 is selling ticket 43
Thread-0 is selling ticket 22
Thread-2 is selling ticket 42
Thread-1 is selling ticket 23
Thread-2 is selling ticket 41
Thread-1 is selling ticket 22
Thread-2 is selling ticket 40
Thread-1 is selling ticket 21
Thread-2 is selling ticket 39
Thread-1 is selling ticket 20
Thread-0 is selling ticket 21
Thread-1 is selling ticket 19
Thread-0 is selling ticket 20
Thread-1 is selling ticket 18
Thread-0 is selling ticket 19
Thread-2 is selling ticket 38
Thread-0 is selling ticket 18
Thread-2 is selling ticket 37
Thread-0 is selling ticket 17
Thread-2 is selling ticket 36
Thread-1 is selling ticket 17
Thread-2 is selling ticket 35
Thread-1 is selling ticket 16
Thread-2 is selling ticket 34
Thread-1 is selling ticket 15
Thread-2 is selling ticket 33
Thread-1 is selling ticket 14
Thread-0 is selling ticket 16
Thread-1 is selling ticket 13
Thread-0 is selling ticket 15
Thread-1 is selling ticket 12
Thread-0 is selling ticket 14
Thread-2 is selling ticket 32
Thread-0 is selling ticket 13
Thread-2 is selling ticket 31
Thread-0 is selling ticket 12
Thread-2 is selling ticket 30
Thread-1 is selling ticket 11
Thread-2 is selling ticket 29
Thread-1 is selling ticket 10
Thread-2 is selling ticket 28
Thread-1 is selling ticket 9
Thread-2 is selling ticket 27
Thread-1 is selling ticket 8
Thread-0 is selling ticket 11
Thread-1 is selling ticket 7
Thread-0 is selling ticket 10
Thread-1 is selling ticket 6
Thread-0 is selling ticket 9
Thread-2 is selling ticket 26
Thread-0 is selling ticket 8
Thread-2 is selling ticket 25
Thread-0 is selling ticket 7
Thread-2 is selling ticket 24
Thread-1 is selling ticket 5
Thread-2 is selling ticket 23
Thread-1 is selling ticket 4
Thread-2 is selling ticket 22
Thread-1 is selling ticket 3
Thread-2 is selling ticket 21
Thread-1 is selling ticket 2
Thread-0 is selling ticket 6
Thread-1 is selling ticket 1
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-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-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-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 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
这是我本机上运行的结果?根本原因在那?有哪位大侠能说说
----------------解决方案--------------------------------------------------------
那是什么开发环境!!!
你本来就是对的。哎
换吧。
用eclipse吧
----------------解决方案--------------------------------------------------------
楼主 由于每台电脑的不同所有使用多线程时出来的结果也是不同的,我觉得如果你的题意是想建三个售票点共卖200张票,而不应该是三个售票点分别卖200张票 所以三个线程应该调用一个t1 即改为
SellTickets t1=new SellTickets();
new Thread(t1).start();
new Thread(t1).start();
new Thread(t1).start();
这样三个线程就共享同一个数据了,结果如下:
Thread-1 is selling ticket 200
Thread-0 is selling ticket 199
Thread-2 is selling ticket 198
Thread-1 is selling ticket 197
Thread-0 is selling ticket 196
Thread-2 is selling ticket 195
Thread-1 is selling ticket 194
Thread-0 is selling ticket 193
Thread-2 is selling ticket 192
Thread-1 is selling ticket 191
Thread-0 is selling ticket 190
Thread-2 is selling ticket 189
Thread-1 is selling ticket 188
Thread-0 is selling ticket 187
Thread-2 is selling ticket 186
Thread-1 is selling ticket 185
Thread-0 is selling ticket 184
Thread-2 is selling ticket 183
Thread-1 is selling ticket 182
Thread-0 is selling ticket 181
Thread-2 is selling ticket 180
Thread-1 is selling ticket 179
----------------解决方案--------------------------------------------------------
回复 7楼 我爱JAVA1
谢谢诸位的解答 ----------------解决方案--------------------------------------------------------