Java ???thread (???)???
???????????? ???????[ 2014/2/19 9:20:48 ] ??????????? Java ????
????6.2.2 ??????: ???1????????????s?? ?????1????Thread?????t?? ??s??????????????t???????. ?????t.start()
????ò??????????.
?????????????:
????new Thread(new M_thrd_2()).start()
????????:
public class M_thread_expl2{
public static void g(){
M_thrd_2 s = new M_thrd_2();
s.id = 1;
Thread t1 = new Thread(s);
t1.start();
Thread t2 = new Thread(s);
s.id = 2;
t2.start();
}
}
??????g() ?????У?
???????????1????M_thrd_2?? ????s.
??????????s??????? ???????????????Thread?????t1 ?? t2. ??????????????.
?????:
????1. ???????????3?????? ????1???????(???g() ????????????). ???????????????? ?????????????????????????????????.
????2. Thread(object ob) ??1????????Thread????????? ???е????ob ???????Runnable ???.
????3. ??????????? ?? ?????t1????????id = 1?? ?????????????t2?????к? t1?????id=2?? ???t1?? ??t2?????????1??????????.
?????????? ???????????????????????.
???????????:
????6.3 ????????????
????1. ???1??????????Thread???????? ???2????????Runnable??????.
????2. ??????: ???1??????????????????start()?????? ???2????????????????????1????Thread????? ???????????start()????.
????3. ?????????????? ??????1????????????????????? ???2 ???????????1?????? ???????Thread????? ????????????????????????????.
??????. ?????????Щ???÷???????.
????7.1 run()
?????????????????е???????д?????????. ?????????. ??? ?????????????1?????????run()????????????? ????????????????????У? ????п??????????.
????7.2 Start()
??????1?????or???????????1??start()????. ????1???????? ??????????run()????.
???????: 1??????????????ù????start()?? ?????start()???????.
????7.3 stop()
??????1??1?????.
????7.4 setName() ?? getName()
???????ú?????????????.
????7.5 Thread.currentThread()
???????????????????static?????? ??????????????????.
???????????????????????????????.
????????1????????A. ????run() ??????????? Thread.currentThread().getName() ????.
??????????????A.run() ????????????(??????A???) ??????? ???????A????????????????.
??????????????A.start()?? ????ú???????A???????????????.
??????? С??
???????????????飬 ??????????????? sleep() ?? wait() ?????н???? ??Щ?????????????. ???????????????????????.
??????
???·???
??????????????????
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