本帖最后由 戎石锁 于 2012-8-28 11:16 编辑
- class Demo
- {
- String name;
- String sex;
- }
- class Input implements Runnable
- {
- private Demo d;
- Input(Demo d)
- {
- this.d=d;
- }
- public void run()
- {
- while(true)
- {
- try
- {
- Thread.sleep(20);
- }
- catch (Exception e)
- {
- System.out.println(e.toString());
- }
- System.out.println(Thread.currentThread().getName()+"存bbbbbb");
- }
- }
- }
- class Output implements Runnable
- {
- private Demo d;
- Output(Demo d)
- {
- this.d=d;
- }
- public void run()
- {
- while(true)
- {
- try
- {
- Thread.sleep(20);
- }
- catch (Exception e)
- {
- System.out.println(e.toString());
- }
- System.out.println(Thread.currentThread().getName()+"取aaaaaaaaaaaaaaa");
- }
- }
- }
- class Demo3
- {
- public static void main(String[] args)
- {
- Demo d = new Demo();
- Output ou = new Output(d);
- Input in = new Input(d);
- Thread t1 = new Thread(in);
- Thread t2 = new Thread(ou);
- t1.start();
- t2.start();
- }
- }
复制代码 我这个需要同步吗? 求详解 详解 详解 详解 详解 详解 |
|