Java?????????????
???????????? ???????[ 2015/5/8 13:51:15 ] ???????????????
????SCJP5?????
??????????????
????1?????java.lang.Thread??
???????????и?run()???????????????÷???
????public void run()
?????????????????????? Runnable ???ж????????????? Runnable ????? run ???????????÷?????????κβ??????????
????Thread ???????????д?÷?????
????2?????java.lang.Runnable????
????void run()
???????????? Runnable ????????????????????????????????????е?????е??????? run ??????
???????? run ?????Э???????????????κ???????????
????????????????
????1??????????java.lang.Thread????????????new???ɡ?
????2????????????java.lang.Runnable??????????Thread?????????
????Thread(Runnable target)
????Thread(Runnable target?? String name)
????Thread(ThreadGroup group?? Runnable target)
????Thread(ThreadGroup group?? Runnable target?? String name)
????Thread(ThreadGroup group?? Runnable target?? String name?? long stackSize)
??????????????
??????????Thread?????????start()????????????run()???????????
?????????start()???????????????????У???????????Thread????????????????????????
?????????start()????????????????и????????
????????μ?????????????μ?????????
????????????????????????????
???????????????????????????run()?????????С?
?????????Java?????run()????????κ???????????main()??????????????????????????????????(?????)????????Runnable?????Thread?????run?????????????????????μ?????
???????????
????1?????Runnable????????????
package com.dashu.thread;
public class DoSomething implements Runnable {
private String name;
public DoSomething(String name) {
this.name = name;
}
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 10; i++) {
for (long k = 0; k < 100000000; k++)
;
System.out.println(name + ": " + i);
}
}
}
package com.dashu.thread;
public class TestThread {
public static void main(String[] args) {
DoSomething do1 = new DoSomething("???");
DoSomething do2 = new DoSomething("????");
Thread t1 = new Thread(do1);
Thread t2 = new Thread(do2);
t1.start();
t2.start();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11