zoukankan      html  css  js  c++  java
  • wait

    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....");
        }
    }
  • 相关阅读:
    获取当前用户的网络状态--iOS
    网络请求 ---iOS
    一个小项目中需要注意的几个地方
    在项目中几个需要学习的知识
    简单三级联动的建立
    验证码在页面中的使用
    嘿嘿。今天学习了AJAX的几个方法
    状态保持以及AJAX的初步学习
    webform的学习(2)
    WebForm的初步认识
  • 原文地址:https://www.cnblogs.com/muhe221/p/7735626.html
Copyright © 2011-2022 走看看