当前位置:网站首页>Difference between thread and process

Difference between thread and process

2022-06-22 06:17:00 Kuxiaoya

The difference between thread and process :

Threads 、 process , If you can't use one sentence Technology , Not solid !

process : A program ,QQ.exe Music.exe A collection of programs ;

A process can often contain multiple threads , At least one !

Java There are several threads by default ?2 individual Namely : main、GC

Threads : Started a process Typora, Write , Save automatically ( The thread is responsible for )

about Java for :Thread、Runnable、Callable

Java Is it really possible to start threads ? Can't drive

Concurrent 、 The difference between parallelism :

Concurrent programming : Concurrent 、 parallel

Concurrent ( Multithreading the same resource )

  • CPU A nucleus , Simulate multiple threads , Fast alternation

parallel ( Many people walk together )

  • CPU Multicore , Multiple threads can execute at the same time

How to view how many processors your computer has ( obtain CPU Check the number ):

The first one is :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-7SBW5xqi-1654846852629)(C:\Users\38492\AppData\Local\Temp\1654784208964.png)]

The second kind :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-sf0PmuMH-1654846852640)(C:\Users\38492\AppData\Local\Temp\1654784242664.png)]

The third kind of :

 Insert picture description here

The nature of concurrent programming : make the best of CPU Resources for

All companies value it !

Threads have several States

public enum State {
    
    // Freshmen 
    NEW,

    // function 
    RUNNABLE,

    // Blocking 
    BLOCKED,

    // wait for , Dead, etc 
    WAITING,

    // Overtime waiting 
    TIMED_WAITING,

    // End 
    TERMINATED;
}

wait/sleep difference

1、 From different classes

wait => Object

sleep => Thread

2、 About the release of the lock

wait Can release the lock ,sleep I went to sleep , Sleep with the lock , Don't release !

3、 The scope of use is different

wait Must be in sync block

sleep You can sleep anywhere

4、 Whether you need to catch exceptions

wait No need to catch exceptions

sleep You have to catch exceptions

原网站

版权声明
本文为[Kuxiaoya]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220609551314.html