Programowanie współbieżne w języku Java
Programowanie współbieżne w języku Java
Programowanie współbieżne w języku Java
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Szkielety interfejsy Egzekutor do zarządzania wątkami, interfejs Callable oraz klasa Future<br />
FixedThreadPoolExcecutor<br />
package thp01;<br />
import java.util.concurrent.ExecutorService;<br />
import java.util.concurrent.Executors;<br />
public class ThreadPoolTest {<br />
public static void main(String[] args) {<br />
int numWorkers = Integer.parseInt(args[0]);<br />
int threadPoolSize = Integer.parseInt(args[1]);<br />
ExecutorService tpes = Executors.newFixedThreadPool(threadPoolSize);<br />
WorkerThread[] workers = new WorkerThread[numWorkers];<br />
for (int i = 0; i < numWorkers; i++) {<br />
workers[i] = new WorkerThread(i);<br />
tpes.execute(workers[i]);<br />
}<br />
tpes.shutdown();<br />
}<br />
}<br />
======================================================================<br />
package thp01;<br />
public class WorkerThread implements Runnable {<br />
private int workerNumber;<br />
WorkerThread (int number) {<br />
workerNumber = number;<br />
}<br />
}<br />
public void run(){<br />
for (int i = 0; i