日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
J2EE線程代碼示例

以下這段代碼可以幫助你學習J2EE線程:

 
 
 
  1. public class TT implements Runnable {  
  2.  int b = 100;  
  3.    
  4.  public synchronized void m1() throws Exception{  
  5.   //Thread.sleep(2000);  
  6.   b = 1000;  
  7.   Thread.sleep(5000);  
  8.   System.out.println("b = " + b);  
  9.  }  
  10.    
  11.  public synchronized void m2() throws Exception {  
  12.   Thread.sleep(2500);  
  13.   b = 2000;  
  14.   System.out.println( b);  
  15.  }  
  16.    
  17.  public void run() {  
  18.   try {  
  19.    m1();  
  20.   } catch(Exception e) {  
  21.    e.printStackTrace();  
  22.   }  
  23.  }  
  24.    
  25.  public static void main(String[] args) throws Exception {  
  26.   TT tt = new TT();  
  27.   Thread t = new Thread(tt);  
  28.   t.start();  
  29.     
  30.   tt.m2();  
  31.   System.out.println(tt.b);  
  32.  }  

函數(shù)運行結果:2000
              2000
              b = 1000

函數(shù)分析:在main函數(shù)中,start了一個線程,即運行了該線程的run方法,run方法中要調用m1方法,而同時在main主線程中調用了m2的方法,注意此時m2鎖定了對象,因此即使m2中有sleep方法,同樣也要等m2結束后m1線程才能運行。


網站標題:J2EE線程代碼示例
文章來源:http://www.5511xx.com/article/cciojgg.html