Biblioteca Java - Blame information for rev 28
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
28 | mihai | 1 | /* |
2 | * ThreadPoolTest.java | ||
3 | */ | ||
4 | package exemple.fire.tpool; | ||
5 | |||
6 | /** | ||
7 | * Class created by @author Mihai HULEA at Feb 22, 2005. | ||
8 | * | ||
9 | * This class is part of the labs project. | ||
10 | * | ||
11 | * Exemplifica folosirea threadpool-urilor folosind pachetul java.util.concurrent | ||
12 | */ | ||
13 | import java.util.concurrent.*; | ||
14 | public class ThreadPoolTest { | ||
15 | public static void main(String[] args) { | ||
16 | |||
17 | //numarul de fire ce vor fi lansate in executie | ||
18 | int numWorkers = 10; | ||
19 | |||
20 | //numarul de fire ce se pot executa in paralel | ||
21 | int threadPoolSize = 3; | ||
22 | |||
23 | //constuieste un nou threadpool cu dimensiune data | ||
24 | ExecutorService tpes = | ||
25 | Executors.newFixedThreadPool(threadPoolSize); | ||
26 | |||
27 | Worker[] workers = new Worker[numWorkers]; | ||
28 | for (int i = 0; i < numWorkers; i++) { | ||
29 | workers[i] = new Worker(i); | ||
30 | tpes.execute(workers[i]); | ||
31 | } | ||
32 | |||
33 | //executor service nu mai accepta noi taskuri | ||
34 | tpes.shutdown(); | ||
35 | } | ||
36 | } |