Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4987f8

Browse files
committed
feat:多线程实现本质上只有两种方式 继承Thread实现run方法和实现Runnable接口的run方法
1 parentcf10e63 commitc4987f8

19 files changed

+92
-0
lines changed
-16 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-500 Bytes
Binary file not shown.
-856 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
-576 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.imood.msjava.thread;
2+
3+
/**
4+
* msJava
5+
*
6+
* @Description
7+
* @Date 2020-11-29
8+
*/
9+
publicclassBothRunnableThread {
10+
11+
publicstaticvoidmain(String[]args) {
12+
newThread(newRunnable() {
13+
@Override
14+
publicvoidrun() {
15+
System.out.println("我来自Runnable");
16+
}
17+
}){
18+
@Override
19+
publicvoidrun() {
20+
System.out.println("我来自Thread");
21+
}
22+
}.start();
23+
24+
/**
25+
* lambda 表达式 创建线程
26+
*/
27+
newThread(()->System.out.println(Thread.currentThread().getName())).start();
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.imood.msjava.thread;
2+
3+
importjava.util.Timer;
4+
importjava.util.TimerTask;
5+
6+
/**
7+
* msJava
8+
*
9+
* @Description 定时器 创建 线程
10+
* @Date 2020-11-29
11+
*/
12+
publicclassDemoTimerTask {
13+
14+
publicstaticvoidmain(String[]args) {
15+
Timertimer =newTimer();
16+
timer.scheduleAtFixedRate(newTimerTask() {
17+
@Override
18+
publicvoidrun() {
19+
System.out.println(Thread.currentThread().getName());
20+
}
21+
},1000,1000);
22+
}
23+
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packagecom.imood.msjava.thread;
2+
3+
/**
4+
* msJava
5+
*
6+
* @Description
7+
* @Date 2020-11-29
8+
*/
9+
publicclassRunnableStyleimplementsRunnable{
10+
@Override
11+
publicvoidrun() {
12+
System.out.println("RunnableStyle ····");
13+
}
14+
15+
publicstaticvoidmain(String[]args) {
16+
Threadthread =newThread(newRunnableStyle());
17+
thread.start();
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.imood.msjava.thread;
2+
3+
4+
/**
5+
* msJava
6+
*
7+
* @Description
8+
* @Date 2020-11-29
9+
*/
10+
publicclassThreadStyleextendsThread {
11+
12+
@Override
13+
publicvoidrun() {
14+
System.out.println("ThreadStyle ····");
15+
}
16+
17+
publicstaticvoidmain(String[]args) {
18+
newThreadStyle().start();
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp