码迷,mamicode.com
首页 > 其他好文 > 详细

wait

时间:2017-10-26 11:53:42      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:run   val   private   i++   log   extends   ble   desc   override   

 

package money.thread;

import money.Log;

public class AddRunner extends ExecutableRunner {

    private static final String TAG = "AddRunner";
    public int a;

    public AddRunner(Object readyTaskListLock, String description, int exclusiveValue, int type) {
        super(readyTaskListLock, description, exclusiveValue, type);
        a = 0;
    }

    @Override
    public void run() {

        while (true) {
            a++;
            Log.d(TAG, "description:" + description + " a:" + a);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if (a == 5) {
                synchronized (readyTaskListLock) {
                    // TODO: modify state
                    readyTaskListLock.notify();
                }
                return;
            }
        }
    }
}

 

package money;

import money.thread.AddRunner;
import money.thread.ExecutableRunner;

public class Test {

    private static final String TAG = "Test";

    public static void main(String[] args) {
        Processor processor = Processor.instance();
        processor.start();

        // wait for the initialization of processor
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        

        for (int i = 0; i < 4; i++) {
            ExecutableRunner runner = new AddRunner(processor.getReadyTaskListLock(), "" + i, 0, 0);
            processor.addTask(runner);
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }            
        }
        
        Log.d(TAG, "to add other task....");
    }
}

 

wait

标签:run   val   private   i++   log   extends   ble   desc   override   

原文地址:http://www.cnblogs.com/muhe221/p/7735626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!