当前位置:网站首页>Introduction to concurrent programming (I)
Introduction to concurrent programming (I)
2022-07-03 12:11:00 【zwanying】
Introduction to concurrent programming ( One )
Why do I have to be concurrent ?
Improve resource utilization , Speed up the program .
Java Memory model :
The working memory : private Each thread allocates independent memory , Mutual interference
Main memory : All processes share
Thread class [implements Runnable]
There are three ways to create a thread :
Inherit Thread class , rewrite run Method , example .start perform
public class ThreadExtendTest extends Thread{ @Override public void run(){ System.out.println("thread success"); } public static void main(String []args){ new ThreadExtendTest().start(); } }Realization Runnable Interface , rewrite run Method ,Thread example .start perform
public class ThreadExtendTest implements Runnable{ @Override public void run(){ System.out.println("thread success"); } public static void main(String []args){ new Thread(new ThreadExtendTest()).start(); }Realization Callable Interface , rewrite call Method , establish FutureTask Get the return value .
public class ThreadCallableTest implements Callable<String>{ @Override public String call(){ return "you are right"; } public static void main(String[] args) throws ExecutionException, InterruptedException { FutureTask<String> futureTask = new FutureTask<>(new ThreadCallableTest()); Thread thread = new Thread(futureTask); thread.start(); System.out.println(futureTask.get()); } }Anonymous inner class Realization Runnable Simple version of interface
public class Test { public static void main(String[] args) { Thread t = new Thread(new Runnable() { @Override public void run() { System.out.println("you area success"); } }); t.start(); } }Thread Methods
run() // Specific operations to be performed start() // perform run() Method sleep() // Sleep n millisecond getName() // Get the thread name setName() // Modify the thread name
边栏推荐
- Slf4j log facade
- Wechat applet development - page Jump transfer parameters
- regular expression
- DEJA_ Vu3d - cesium feature set 053 underground mode effect
- Dart: self study system
- Differences between MySQL Union and union all
- Flutter: about monitoring on flutter applications
- 023 ([template] minimum spanning tree) (minimum spanning tree)
- Interview experience in summer camp of Central South University in 2022
- C language improvement article (wchar_t) character type
猜你喜欢

Vulnhub's presidential

(构造笔记)ADT与OOP

Unicode encoding table download

Itext7 uses iexternalsignature container for signature and signature verification

Wechat applet - basic content

OPenGL 基本知识(根据自己理解整理)

XML (DTD, XML parsing, XML modeling)

vulnhub之GeminiInc v2

Download address and installation tutorial of vs2015

Socket TCP for network communication (I)
随机推荐
STL tutorial 10 container commonalities and usage scenarios
Cacti monitors redis implementation process
Wechat applet - basic content
OpenGL index cache object EBO and lineweight mode
Itext7 uses iexternalsignature container for signature and signature verification
Ripper of vulnhub
QT OpenGL rotate, pan, zoom
网络通讯之Socket-Tcp(一)
Laravel time zone timezone
laravel 时区问题timezone
Test classification in openstack
Go language to realize static server
Notes on 32-96 questions of sword finger offer
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
Systemverilog-- OOP--对象的拷贝
C language improvement article (wchar_t) character type
(构造笔记)MIT reading部分学习心得
PHP get the file list and folder list under the folder
vulnhub之Ripper
vulnhub之cereal