Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132937 views
License: OTHER
1
public final class StringTask implements Runnable {
2
int id;
3
public StringTask(int id) {
4
this.id = id;
5
}
6
public void run() {
7
// do calculation
8
}
9
}
10
11
ExecutorService pool =
12
Executors.newFixedThreadPool(4);
13
for(int i = 0; i < 10; i++){
14
pool.execute(new StringTask(i));
15
}
16
pool.shutdown();
17
executor.awaitTermination();
18