Code Monkey home page Code Monkey logo

multithread's Introduction

一、线程8大核心

1.实现多线程的方法到底为1种,2种还是4种?

1)总体介绍:网上搜索有各种说法
2)错误的理解:
3)正确的理解:2种,Oracle官网文档(
    一种声明thread类;run()整个都被重写 缺点:没有解耦
    另一种方法是一个实现Runnable接口的类,然后该类实现run方法;最终调用target.run() 该方法更好:解耦 资源节约
    )
    1.从代码架构角度:具体的任务(run方法)应该和“创建和运行线程的机制(Thread类)”解耦,用runnable对象可以实现解耦。
    2.使用继承Thread的方式的话,那么每次想新建一个任务,只能新建一个独立的线程,而这样做的损耗会比较大
    (比如重头开始创建一个线程、执行完毕以后再销毁等。如果线程的实际工作内容,也就是run()函数里只是简单的打印一行文字的话,
    那么可能线程的实际工作内容还不如损耗来的大)。如果使用Runnable和线程池,就可以大大减小这样的损耗。
    3.继承Thread类以后,由于Java语言不支持双继承,这样就无法再继承其他的类,限制了可扩展性。
    
    src.threadcoreknowledge.createthreads

2.启动线程的正确和错误的方法

1)start()和run()的比较
2)start()方法原理解读
3)run()方法原理解读
4)常见面试题

3.如何停止线程?

1)原理介绍
2)如何正确停止线程
3)错误的停止方法
4)停止线程相关的重要函数解析
5)常见面试问题

4.线程的6个状态(线程的生命周期)

5.Thread和Object类种和线程相关的重要方法

6.线程各属性

7.线程的未捕获一场UncaughtException应该如何处理?

8.多线程会导致性能问题(线程引入的开销、上下文切换)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.