barefoot icon indicating copy to clipboard operation
barefoot copied to clipboard

what is the function of scheduler package?

Open CallumWang opened this issue 6 years ago • 1 comments

Hello: I found the schedular usage in Matcher.java. However, it seems that it is related to something about Cocurrent. What is the meaning of it in this "for block".

for (final MatcherCandidate predecessor : predecessors.two()) {
            scheduler.spawn(new Task() {
                @Override
               //something to run.
                }
            });
        }

If I don't use the schedular,what will happen?Does it make any different? Looking forward to your reply. Thanks a lot.

CallumWang avatar Sep 20 '18 14:09 CallumWang

The scheduler package is for parallelization of route computations. Since we usually have some number, say n, of matching candidates for each position measurement, we must calculate approximagely n^2 routes. The route computation is a single-source-multiple-target step such that we still have n such computations which we can parallelize here. Note, we have here a simple work-stealing adaptation implemented, which is the scheduler package, because thread pools of the JRE are AFAIK not designed for stream workloads, i.e., there is NO guarantee on the order of processing like a FIFO order such that there is no guarantee that one job finishes if you consistently add more jobs in a stream processing fashion. To answer your question more precisely, for each predecessor we spawn a task that does the single-source-multiple-target computation where tasks may be executed in parallel with respect to the number of worker threads or processor cores we have available. This is similar to: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html

smattheis avatar Sep 23 '18 08:09 smattheis