test.java
来自「实例精华」· Java 代码 · 共 81 行
JAVA
81 行
public class Test
{
public static void main(String[] args)
{
Hollow h = new Hollow();
Producer p = new Producer(h);
Consumer c = new Consumer(h);
p.start();
c.start();
}
}
class Producer extends Thread
{
Hollow h;
public Producer(Hollow h)
{
this.h=h;
}
public void run()
{
for (int i = 0; i<10; i++)
{
h.put(i);
System.out.println("put:"+i);
}
}
}
class Hollow
{
int value;
public void put(int value)
{
this.value=value;
}
public int get()
{
return this.value;
}
}
class Consumer extends Thread
{
Hollow h;
public Consumer(Hollow h)
{
this.h=h;
}
public void run()
{
while(true)
System.out.println("get:"+h.get());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?