题目描述
我用synchronized锁住循环语句,如果循环次数低于400次就能够锁住,如果大于400就锁不住了,请问这是什么原因?
相关代码
private void createThread(){
thread1=new Thread1();
thread2=new Thread1();
thread1.start();
thread2.start();
}
class Thread1 extends Thread{
@Override
public synchronized void run() {
super.run();
for(int i=0;i<500;i++){
MainTool.log(Thread.currentThread().getName()+":"+i);
}
}
}
错误展示
.....
Thread-1:57
Thread-1:58
Thread-1:59
Thread-1:60
Thread-1:61
Thread-1:62
Thread-1:63
Thread-1:64
Thread-1:65
Thread-1:66
Thread-1:67
Thread-1:68
Thread-1:69
Thread-1:70
Thread-1:71
Thread-1:72
Thread-1:73
Thread-1:74
Thread-1:75
Thread-1:76
Thread-1:77
Thread-1:78
Thread-1:79
Thread-1:80
Thread-1:81
Thread-1:82
Thread-1:83
Thread-1:84
Thread-1:85
Thread-1:86
Thread-1:87
Thread-1:88
Thread-1:89
Thread-1:90
Thread-1:91
Thread-1:92
Thread-1:93
Thread-1:94
Thread-1:95
Thread-1:96
Thread-1:97
Thread-1:98
Thread-1:99
Thread-0:72
Thread-0:73
Thread-0:74
Thread-0:75
Thread-0:76
Thread-0:77
Thread-0:78
Thread-0:79
Thread-0:80
Thread-0:81
Thread-0:82
Thread-0:83
Thread-0:84
Thread-0:85
Thread-0:86
Thread-0:87
Thread-0:88
Thread-0:89
Thread-0:90
Thread-0:91
Thread-0:92
Thread-0:93
Thread-0:94
Thread-0:95
Thread-0:96
Thread-0:97
Thread-0:98
Thread-0:99
Thread-0:100
Thread-0:101
Thread-0:102
Thread-0:103
Thread-0:104
Thread-0:105
Thread-0:106
Thread-0:107
Thread-0:108
Thread-0:109
Thread-0:110
Thread-0:111
Thread-0:112
Thread-0:113
Thread-0:123
Thread-1:109
Thread-0:124
Thread-1:110
Thread-0:125
Thread-1:111
Thread-0:126
Thread-1:112
Thread-0:127
Thread-1:113
Thread-0:128
Thread-0:136
Thread-0:137
Thread-0:138
Thread-0:139
Thread-0:140
Thread-0:141
Thread-0:142
Thread-0:143
Thread-0:144
Thread-1:114
Thread-0:178
Thread-1:121
Thread-0:186
Thread-1:122
Thread-0:187
Thread-1:123
Thread-0:188
Thread-1:124
Thread-1:125
Thread-1:126
Thread-1:127
Thread-1:128
Thread-1:129
Thread-1:130
Thread-1:131
Thread-1:132
Thread-1:133
Thread-1:134
Thread-1:135
Thread-1:136
Thread-1:137
Thread-1:138
Thread-1:139
Thread-1:140
Thread-1:141
Thread-1:142
Thread-1:143
Thread-1:144
Thread-1:145
Thread-1:146
Thread-1:147
Thread-1:148
Thread-1:149
Thread-1:150
Thread-1:151
Thread-1:152
Thread-1:153
Thread-1:154
Thread-1:155
Thread-1:156
Thread-1:157
Thread-1:158
Thread-1:159
Thread-1:160
Thread-1:161
Thread-1:162
Thread-1:163
Thread-1:164
Thread-1:165
Thread-1:166
Thread-1:167
Thread-1:168
Thread-1:169
Thread-1:170
Thread-1:171
Thread-1:172
Thread-1:173
Thread-1:174
Thread-1:175
Thread-1:176
Thread-1:177
Thread-1:178
Thread-1:179
Thread-1:180
Thread-1:181
Thread-0:189
Thread-1:182
Thread-1:183
Thread-1:184
Thread-1:185
Thread-1:186
Thread-0:190
Thread-1:187
Thread-0:191
Thread-1:188
Thread-0:192
Thread-1:189
Thread-0:193
Thread-1:190
Thread-0:194
Thread-1:191
Thread-0:195
Thread-1:192
Thread-0:196
Thread-1:193
Thread-0:197
Thread-1:194
Thread-0:198
Thread-1:195
Thread-0:199
Thread-1:196
Thread-0:200
Thread-1:197
Thread-0:201
Thread-1:198
Thread-0:202
Thread-1:199
Thread-0:203
Thread-1:200
Thread-0:204
Thread-1:201
Thread-0:205
Thread-1:202
Thread-0:206
Thread-1:203
Thread-0:207
Thread-1:204
Thread-0:208
.....
添加回答
举报
0/150
提交
取消