代码:- <p>import java.util.concurrent.*;
- class Resource
- {
- private String name;
- private String sex;
- ReentrantLock lock = new ReentrantLock();
- Condition con = lock.newCondition();</p><p> void set(String name, String sex)
- {
- this.name = name;
- this.sex = sex;
- }
-
- void get()
- {
- System.out.println(name+"^^^^^^^"+sex);
- }
- }</p><p>class Input implements Runnable
- {
- private Resource res;
- int s=0;
- Input(Resource res)
- {
- this.res = res;
- }
- public void run()
- {
- for (int i=0; i<8000 ; i++ )
- {
- if (s == 0)
- res.set("lili", "girl");
- else
- res.set("李华", "男");
- s=(s+1)%2;
- }
-
- }
- }</p><p>class Output implements Runnable
- {
- private Resource res;
- Output(Resource res)
- {
- this.res = res;
- }
- public void run()
- {
- for (int i=0; i<8000 ; i++ )
- {
- res.get();
- }
-
- }
- }</p><p>class LockDemo
- {
- public static void main(String[] args)
- {
- //System.out.println("Hello World!");
- Resource r = new Resource();
- Input in = new Input(r);
- Output out = new Output(r);</p><p> Thread t1 = new Thread(in);
- Thread t2 = new Thread(out);</p><p> t1.start();
- t2.start();
- }
- }
- </p><p> </p>
复制代码 编译出现了问题(如下图):
为什么会出现这样的错误,我已经将包导入了,!!
是不是因为我的jdk版本不对??
如何查看jdk版本呢?
|