当前位置:首页 » 编程语言 » javaappend

javaappend

发布时间: 2022-08-25 15:39:13

java中log.append怎么用,什么意思

log是StringBuffer或者StringBuilder
log.append()就是在字符串后面追加内容
例如:
StringBuilder log=new StringBuilder();
log.append("hello");
System.out.println(log); //输出hello
log.append("World");
System.out.println(log); //输出helloWorld

Ⅱ java中append方法有什么用 builder对象可以代表哪些字符 方法的参数什么情况下需

java中append方法的作用是追加字符串。
builder对象可以代表任何字符串
字符串都需要加引号。

Ⅲ java append错误怎么解决

这样吧,我是根据前面同学的思路以生产者-消费者方式完成的一个java小demo。

第一个类:
共享值类。
public class ShareValue {
private int count;
public ShareValue(int count) {
this.count = count;
}
public synchronized void plus() throws InterruptedException {
if (count <= 100) {
++count;
System.out.println("Procer:" + count);
this.notifyAll();
} else {
System.out.println("值超过100,停止增加!");
this.wait();
}
}
public synchronized void minus() throws InterruptedException {
if (count > 0) {
--count;
System.err.println("Consumer:" + count);
this.notifyAll();
} else {
System.out.println("值小或等于0,停止减少!");
this.wait();
}
}
}

第二个类:
生产者类
public class Procer implements Runnable {
private ShareValue value;
public Procer(ShareValue value) {
this.value = value;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
try {
value.plus();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

第三个类:
消费者类
public class Consumer implements Runnable {
private ShareValue value;
public Consumer(ShareValue value) {
this.value = value;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
try {
value.minus();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

第四个:
测试类
public class TestPC {
public static void main(String[] args) {
ShareValue value = new ShareValue(0);
Runnable pr = new Procer(value);
Runnable cr = new Consumer(value);
new Thread(pr).start();
new Thread(cr).start();
}
}

希望对你有所帮助,这只是能初步跑起来,可以观察运行,后面可以逐步调整。

热点内容
苹果手机如何退出ad密码 发布:2025-05-13 19:35:24 浏览:352
资本论中央编译局 发布:2025-05-13 19:21:50 浏览:134
python路径是否存在 发布:2025-05-13 19:08:38 浏览:570
保时捷卡宴哪个配置比较好 发布:2025-05-13 19:00:08 浏览:725
c语言负数运算 发布:2025-05-13 18:45:21 浏览:428
太空杀电脑版连接不到服务器 发布:2025-05-13 18:40:19 浏览:457
同样的配置为什么跑分不同 发布:2025-05-13 18:39:06 浏览:278
获取linuxcpu序列号 发布:2025-05-13 18:36:35 浏览:738
appleid为什么连接服务器出现问题 发布:2025-05-13 18:17:37 浏览:972
书翁怎么配置 发布:2025-05-13 18:17:36 浏览:911