av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

如何實(shí)現(xiàn)Java多線性同步讀寫數(shù)據(jù)

Java多線性同步進(jìn)行是一個(gè)很重要的東西,我們不少的時(shí)候都需要用到這些代碼。但是有人還不能很好的進(jìn)行讀寫同步的相關(guān)代碼編寫。下面我們就看看如何才能正確的進(jìn)行Java多線性同步的編寫。

創(chuàng)新互聯(lián)公司主營(yíng)臨武網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件定制開發(fā),臨武h5重慶小程序開發(fā)搭建,臨武網(wǎng)站營(yíng)銷推廣歡迎臨武等地區(qū)企業(yè)咨詢

 
 
 
  1. public class SynTest ...{
  2. private String firstName, lastName;
  3. private synchronized String getName() ...{
  4. String result = firstName + " " + lastName;
  5. return result;
  6. }
  7. private synchronized void setName(String firstName,
     String lastName) ...{
  8. print("entering setName");
  9. this.firstName = firstName;
  10. print("Set first name have done firstName=" + 
    this.firstName);
  11. try ...{
  12. Thread.sleep(1000);
  13. } catch (InterruptedException e) ...{
  14. }
  15. this.lastName = lastName;
  16. print("set last name have done,and leave setName() 
    method.firstName="
  17. + this.firstName + " lastName=" + this.lastName);
  18. }
  19. private static void print(String msg) ...{
  20. String thread = Thread.currentThread().getName();
  21. System.out.println(thread + ": " + msg);
  22. }
  23. public static void main(String[] args) ...{
  24. // 必需聲明為final,否則runnable里面的run()方法不能訪問。
  25. final SynTest test1 = new SynTest();
  26. // 設(shè)置初始值
  27. test1.setName("arzu", "guli");
  28. Runnable run1 = new Runnable() ...{
  29. public void run() ...{
  30. test1.setName("kang", "midi");
  31. }
  32. };
  33. // 修改名字線程
  34. Thread threadOne = new Thread(run1, "threadOne");
  35. threadOne.start();
  36. try ...{
  37. Thread.sleep(200);
  38. } catch (InterruptedException e) ...{
  39. }
  40. Runnable run2 = new Runnable() ...{
  41. public void run() ...{
  42. print("讀取" + test1.getName());
  43. }
  44. };
  45. // 讀取名字線程
  46. Thread threadTwo = new Thread(run2, "threadTwo");
  47. threadTwo.start();
  48. System.out.println("main() exit");
  49. }
  50. }

以上就是對(duì)Java多線性同步的詳細(xì)介紹。


分享文章:如何實(shí)現(xiàn)Java多線性同步讀寫數(shù)據(jù)
網(wǎng)頁(yè)地址:http://uogjgqi.cn/article/djgcjpo.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流