我想知道是否存在一种在Java(或有框架或库)中并行化查询的方法,如C#和Linq:
var query = from item in source.AsParallel().WithDegreeOfParallelism(2)
where Compute(item) > 42
select item;
如果我不能并行化查询,如果我可以在c#中做这样的事情(每个并行化的a):
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);
}
如果您发布任何框架或图书馆,请告诉我您的体验? 你的时间。
关于c#和linq,你可以在这里找到文档:http://msdn.microsoft.com/en-us/library/dd997425.aspx