All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lambda.query.ParallelLoops Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package org.lambda.query;

import com.spun.util.LambdaThreadLauncher;
import org.lambda.actions.Action1;

import java.util.concurrent.atomic.AtomicInteger;

public class ParallelLoops
{
  public static  void forEach(Iterable list, final Action1 a1)
  {
    final AtomicInteger done = new AtomicInteger();
    int count = 0;
    for (T i : list)
    {
      count++;
      final T piece = i;
      new LambdaThreadLauncher(() -> {
        a1.call(piece);
        done.incrementAndGet();
      });
    }
    while (done.get() != count)
    {
      try
      {
        Thread.sleep(2);
      }
      catch (InterruptedException e)
      {
        // do nothing
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy