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

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

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:515
微博数据库设计 发布:2025-07-05 15:30:55 浏览:19
linux485 发布:2025-07-05 14:38:28 浏览:299
php用的软件 发布:2025-07-05 14:06:22 浏览:748
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:423
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:682
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:231
java的开发流程 发布:2025-07-05 12:45:11 浏览:676
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:275
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:825