Skip to content

Commit 967a837

Browse files
author
crazy
committed
12
1 parent 95b83da commit 967a837

7 files changed

Lines changed: 114 additions & 2 deletions

File tree

JavaBase/.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5-
<classpathentry kind="lib" path="D:/Program Files/eclipse/log4j-1.2.17.jar"/>
6-
<classpathentry kind="lib" path="D:/Program Files/eclipse/lombok.jar"/>
5+
<classpathentry kind="lib" path="D:/eclipse/log4j-1.2.17.jar"/>
6+
<classpathentry kind="lib" path="D:/eclipse/lombok.jar"/>
77
<classpathentry kind="output" path="bin"/>
88
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com._520it.thread;
2+
3+
/**
4+
* 此为通过继承方式创建线程
5+
* @author crazyxia
6+
*
7+
*/
8+
public class ExtendThreadDemo extends Thread{
9+
10+
@Override
11+
public void run() {//重写run方法
12+
for (int i=0;i<100;i++){
13+
System.out.println("当前线程"+Thread.currentThread().getName()+i);
14+
}
15+
}
16+
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com._520it.thread;
2+
3+
/**通过实现runnable接口创建线程
4+
* @author crazyxia
5+
*
6+
*/
7+
public class ImplementRunnableThreadDemo implements Runnable {
8+
9+
@Override
10+
public void run() {//重写run方法
11+
for(int i =0;i<100;i++){
12+
System.out.println("当前线程为"+Thread.currentThread().getName()+i);
13+
}
14+
15+
16+
}
17+
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com._520it.thread;
2+
3+
/**
4+
* 测试通过继承方式实现的线程
5+
* @author crazyxia
6+
*
7+
*/
8+
public class TestExtendThread {
9+
public static void main(String[] args){
10+
System.out.println("当前线程为"+Thread.currentThread().getName());
11+
for(int i=0;i<100;i++){
12+
System.out.println("当前线程为"+Thread.currentThread().getName()+i);
13+
if(i==50){
14+
Thread etd=new ExtendThreadDemo();
15+
etd.start();
16+
}
17+
}
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com._520it.thread;
2+
3+
/**
4+
* 测试通过实现runnable接口完成的线程
5+
*
6+
* @author crazyxia
7+
*
8+
*/
9+
public class TestImplementsRunnable {
10+
11+
public static void main(String[] args) {
12+
for (int i = 0; i < 100; i++) {
13+
System.out.println("当前线程:" + Thread.currentThread().getName());
14+
if(i==10){
15+
/*Runnable ThreadDemo=new ImplementRunnableThreadDemo(); //class ThreadDemo=
16+
//new ImplementRunnableThreadDemo();
17+
//创建一个接口的实现类
18+
Thread threadRunnableDemo=new Thread(ThreadDemo);*/
19+
Thread threadRunnableDemo=new Thread(new ImplementRunnableThreadDemo());
20+
threadRunnableDemo.start();
21+
22+
}
23+
}
24+
}
25+
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.cnblog.corn;
2+
3+
/**
4+
* 通过继承thread类,重写thread的run方法
5+
* @author crazyxia
6+
*
7+
*/
8+
public class MyThread extends Thread {
9+
10+
@Override
11+
public void run() {
12+
for(int i=0;i<100;i++){
13+
System.out.println(Thread.currentThread().getName()+""+i);
14+
}
15+
}
16+
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.cnblog.corn;
2+
3+
public class ThreadTest {
4+
public static void main(String[] args){
5+
for(int i=0;i<100;i++){
6+
System.out.println(Thread.currentThread().getName()+""+i);
7+
if(i==30){
8+
Thread myThread1=new MyThread();//
9+
Thread myThread2=new MyThread();
10+
myThread1.start();
11+
myThread2.start();
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)