-
- class Tick implements Runnable
- {
- private int tick = 50;
-
- Object obj = new Object();
-
- public void run()
- {
-
- while(true)
- {
- synchronized(obj)
- {
- if(tick > 0)
- {
-
- System.out.println( Thread.currentThread().getName() + " sail --" + tick--);
- }
- }
- }
- }
- }
-
- class TickDemo
- {
- public static void main(String []args)
- {
- Tick t = new Tick();
-
- Thread t1 = new Thread(t);
- Thread t2 = new Thread(t);
- Thread t3 = new Thread(t);
- Thread t4 = new Thread(t);
-
- t1.start();
- t2.start();
- t3.start();
- t4.start();
-
- }
- }
posted @
2016-12-05 22:36
强者心
阅读(
192)
评论()
编辑
收藏
举报