Question

i would like to know whether exist a way to parallelize queries in Java (or there is framework or a library) like in C# and Linq:

var query = from item in source.AsParallel().WithDegreeOfParallelism(2)
        where Compute(item) > 42
        select item;

and if i can't parallelize queries if i can do something like this in c# (a for each parallelized) :

  Parallel.ForEach(files, currentFile =>
        {
            // The more computational work you do here, the greater  
            // the speedup compared to a sequential foreach loop. 
            string filename = System.IO.Path.GetFileName(currentFile);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(currentFile);

            bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            bitmap.Save(System.IO.Path.Combine(newDir, filename));

            // Peek behind the scenes to see how work is parallelized. 
            // But be aware: Thread contention for the Console slows down parallel loops!!!
            Console.WriteLine("Processing {0} on thread {1}", filename,
                                Thread.CurrentThread.ManagedThreadId);

        } 

please if you post any framework or library, can you tell me the experience that you had with it ? thx for your time.

about c# and linq you can find here the documentation : http://msdn.microsoft.com/en-us/library/dd997425.aspx

Was it helpful?

Solution

There isn't a direct translation. Firstly Java doesn't have LINQ nor does it have any standard parallel collection classes.

GPars is perhaps closest fit.

Note that while it is targeted at groovy it's API is perfectly usable from java

OTHER TIPS

Maybe Fork/Join Framework can help you ? Here is java tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top