public static void main(String[] args) {
StringBuilders sb = new StringBuilders();
new Thread(new Tisk1(sb), "存").start();;
new Thread(new Tisk2(sb), "取").start();
}
}
class StringBuilders{
StringBuilder sb = new StringBuilder();
Boolean flog = false;
public void add(){
while(flog){
synchronized (sb) {
for (int x = 0; x < 10; x++) {//向缓冲区中添加东西
sb.append(x+",");
}
flog = true;
}
public class ThreadTests {
public static void main(String[] args) {
StringBuilders sb = new StringBuilders();
new Thread(new Tisk1(sb), "存").start();;
new Thread(new Tisk2(sb), "取").start();
}
}
class StringBuilders{
StringBuilder sb = new StringBuilder();
Boolean flog = true;//标记改动
public void add(){
while(flog){
synchronized (sb) {
for (int x = 0; x < 10; x++) {//向缓冲区中添加东西
sb.append(x+",");
}
flog = false;//标记改动