zoukankan      html  css  js  c++  java
  • 实现线程的多种方式

    1.继承Thread

    public class Thread01 extends Thread {
        @Override
        public void run() {
            System.out.println("继承Thread");
        }
    
        public static void main(String[] args) {
            Thread01 thread01 = new Thread01();
            thread01.start();
        }
    }

    2.实现Runnable

    public class Runnable01 implements Runnable {
        @Override
        public void run() {
            System.out.println("实现Runnable");
        }
    
        public static void main(String[] args) {
            Thread thread = new Thread(new Runnable01());
            thread.start();
        }
    }
    

      

    3.实现Callable

    public class Callable01 implements Callable<String> {
        @Override
        public String call() throws Exception {
            return "实现 Callable";
        }
    
        public static void main(String[] args) throws ExecutionException, InterruptedException {
            FutureTask task = new FutureTask(new Callable01());
            new Thread(task).start();
            System.out.printf("内容 "+task.get());
        }
    }
    

      源码截图

     

       

    线程的多种状态

    public enum State {
            /**
             * 初始状态,尚未启动
             */
            NEW,
    
            /**
             * 可运行状态,可随时运行
             */
            RUNNABLE,
    
            /**
             *  线程阻塞,
             */
            BLOCKED,
    
            /**
             * 等待状态
             */
            WAITING,
    
            /**
             * 指定时间等待*/
            TIMED_WAITING,
    
            /**
             * 线程已完成执行
             */
            TERMINATED;
        }

    xxxx

  • 相关阅读:
    ios开发 MJExtension
    ios开发 time profile用法
    ios开发 UIApplication
    ios AFNetWorking
    ios开发 为什么NSString、NSArray、NSDIctionary用copy修饰
    ios动画
    ios开发GCD
    重要链接
    记录,员工关心的内容。
    怎样用 Wise Installation System 制作汉化补丁?(转)
  • 原文地址:https://www.cnblogs.com/huan30/p/12482952.html
Copyright © 2011-2022 走看看