当前位置:首页 » 编程语言 » 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();
}
}

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

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:568
制作脚本网站 发布:2025-10-20 08:17:34 浏览:857
python中的init方法 发布:2025-10-20 08:17:33 浏览:556
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:738
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:659
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:978
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:231
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:89
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:781
python股票数据获取 发布:2025-10-20 07:39:44 浏览:684