国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - Java并發(fā)程序入門介紹

Java并發(fā)程序入門介紹

2019-12-14 14:49Microgoogle JAVA教程

這篇文章主要介紹了Java并發(fā)程序入門 ,需要的朋友可以參考下

今天看了看Java并發(fā)程序,寫一寫入門程序,并設置了線程的優(yōu)先級。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Elem implements Runnable{
  public static int id = 0;
  private int cutDown = 5;
  private int priority;
  
  public void setPriority(int priority){
    this.priority = priority;
  }
  
  public int getPriority(){
    return this.priority;
  }
  public void run(){
    Thread.currentThread().setPriority(priority);
    int threadId = id++;
    while(cutDown-- > 0){
      double d = 1.2;
      while(d < 10000)
        d = d + (Math.E + Math.PI)/d;
      System.out.println("#" + threadId + "(" + cutDown + ")");
    }
  }
}
public class Basic {
  public static void main(String args[]){
    for(int i = 0; i < 10; i++){
      Elem e = new Elem();
      if(i == 0 )
        e.setPriority(Thread.MAX_PRIORITY);
      else
        e.setPriority(Thread.MIN_PRIORITY);
      Thread t = new Thread(e);
      t.start();
    }
  }
}

由于機器很強悍,所以先開始并沒看到并發(fā)的效果,感覺是按順序執(zhí)行的,所以在中間加了浮點數(shù)的運算來延遲時間。

當然,main函數(shù)里面可以用Executors來管理線程。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.concurrent.*;
class Elem implements Runnable{
  public static int id = 0;
  private int cutDown = 5;
  private int priority;
  
  public void setPriority(int priority){
    this.priority = priority;
  }
  
  public int getPriority(){
    return this.priority;
  }
  public void run(){
    Thread.currentThread().setPriority(priority);
    int threadId = id++;
    while(cutDown-- > 0){
      double d = 1.2;
      while(d < 10000)
        d = d + (Math.E + Math.PI)/d;
      System.out.println("#" + threadId + "(" + cutDown + ")");
    }
  }
}
public class Basic {
  public static void main(String args[]){
//    for(int i = 0; i < 10; i++){
//      Elem e = new Elem();
//      if(i == 0 )
//        e.setPriority(Thread.MAX_PRIORITY);
//      else
//        e.setPriority(Thread.MIN_PRIORITY);
//      Thread t = new Thread(e);
//      t.start();
//    }
    ExecutorService exec = Executors.newCachedThreadPool();
    for(int i = 0; i < 10; i++){
      Elem e = new Elem();
      if(i == 0 )
        e.setPriority(Thread.MAX_PRIORITY);
      else
        e.setPriority(Thread.MIN_PRIORITY);
      exec.execute(e);
    }
    exec.shutdown();
  }
}

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 五月婷婷导航 | 欧美日韩国产精品 | 亚洲a网| 亚洲精品乱码久久久久久金桔影视 | 一久久久 | 亚洲国产精品久久人人爱 | 国产亚洲精品美女久久久久久久久久 | 亚洲欧美日韩一区 | 伊人五月 | 欧美一级特黄aaaaaaa在线观看 | 亚洲天堂中文 | 亚洲精品美女 | 中文字幕国产一区 | 精品国产黄a∨片高清在线 黄色大片aaaa | av网站网址| 亚洲视频在线观看免费 | 久在线看| av免费观看网站 | 49vv看片免费 | 日韩成人影院 | 日韩中文字幕在线 | 国产精品无码久久久久 | 二区三区在线 | 一级片在线观看网站 | 成人精品一区二区三区中文字幕 | 国产精品一区二区无线 | 性欧美另类 | 国产精品3区 | 亚洲精品视频在线免费播放 | 久久精品色欧美aⅴ一区二区 | 午夜av毛片 | 国产亚洲一区二区精品 | 亚洲激情中文字幕 | 久久中文字幕一区二区 | 影音先锋亚洲精品 | 999精品视频一区二区三区 | 免费黄色小视频 | 动漫卡通精品一区二区三区介绍 | 亚洲欧洲视频在线 | 久久av一区二区三区 | 色女人的天堂 |