import java.util.*; import java.util.concurrent.*; // ... ExecutorService exec = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors()); try { for (int i = 0; i < num_of_runs; i++) { exec.submit(new Runnable() { @Override public void run() { // do stuff in num_of_runs times through a 2*#CPU threadpool } }); } } finally { exec.shutdown(); }
According to The Directive 2009/24/EC of the European Parliament and of the Council, and Sec.103(f) of the DMCA (17 U.S.C. § 1201 (f)), the reverse engineering act committed to creating these blog posts is considered legal, as this is an original attempt to improve interoperability, and cannot be waived by license agreements.
The views expressed on this blog are my own and do not necessarily reflect the views of my past and present employers.
2013-08-30
Java: Simple multithreading a piece of code
Labels:
anonymous
,
concurrency
,
concurrent
,
inline
,
java
,
runnable
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment