List of usage examples for java.util.concurrent ForkJoinPool ForkJoinPool
public ForkJoinPool()
From source file:Main.java
public static void main(String[] args) { ForkJoinPool pool = new ForkJoinPool(); IntSum task = new IntSum(3); long sum = pool.invoke(task); System.out.println("Sum is " + sum); }
From source file:Main.java
public static void main(String[] args) { ForkJoinPool fjPool = new ForkJoinPool(); int[] a = new int[3333344]; for (int i = 0; i < a.length; i++) { int k = (int) (Math.random() * 22222); a[i] = k;// w w w. j a va 2 s . c o m } ForkJoinQuicksortTask forkJoinQuicksortTask = new ForkJoinQuicksortTask(a, 0, a.length - 1); long start = System.nanoTime(); fjPool.invoke(forkJoinQuicksortTask); System.out.println("Time: " + (System.nanoTime() - start)); }
From source file:Test.java
public static void main(String[] args) { int numbers[] = new int[100000]; ForkJoinPool forkJoinPool = new ForkJoinPool(); long result = forkJoinPool.invoke(new SumOfSquaresTask(0, numbers.length)); System.out.println("forkJoinPool: " + forkJoinPool.toString()); System.out.println("forkJoinPool: " + forkJoinPool.toString()); System.out.println("Sum of squares: " + result); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { executors = new ForkJoinPool(); List<Long> sequence = new ArrayList<>(); for (int i = 0; i < 20; i++) { sequence.add(fib(i));//from w ww . ja v a2 s. c o m } System.out.println(sequence); }
From source file:Main.java
public static void main(String[] args) throws Exception { int size = 100000; int[] v1 = new int[size]; for (int i = 0; i < size; i++) { v1[i] = i;/*from w w w. j ava 2 s . co m*/ } for (SEQ_THRESHOLD = 10; SEQ_THRESHOLD < size; SEQ_THRESHOLD += 50) { double avgTime = 0.0; int samples = 5; for (int i = 0; i < samples; i++) { long startTime = System.nanoTime(); ForkJoinPool fjp = new ForkJoinPool(); fjp.invoke(new MyAction(0, size, v1)); long endTime = System.nanoTime(); double secsTaken = (endTime - startTime) / 1.0e9; avgTime += secsTaken; } System.out.println(SEQ_THRESHOLD + " " + (avgTime / samples)); } }
From source file:de.science.hack.meshbuilding.MeshBuilder.java
public MeshBuilder() { pool = new ForkJoinPool(); }
From source file:com.kegare.caveworld.util.Version.java
public static void versionCheck() { if (!CURRENT.isPresent() || !LATEST.isPresent()) { initialize();// ww w.j a v a 2 s. c o m } new ForkJoinPool().execute(new Version()); }
From source file:org.rhwlab.BHCnotused.ThreadedAlgorithm.java
public void init(int seg) throws Exception { clusters = new ArrayList<>(); // build the initial clusters with one data point in each cluster for (int n = 0; n < source.getK(); ++n) { RealVector v = source.getCenter(n); Dfp[] z = new Dfp[v.getDimension()]; for (int i = 0; i < z.length; ++i) { z[i] = field.newDfp(v.getEntry(i)); }/*from w ww. j a va 2 s . c o m*/ LabeledFieldVector fv = new LabeledFieldVector(z, n); Cluster cluster = new Cluster(new GaussianGIWPrior(fv)); clusters.add(cluster); } // make all possible pairings of initial clusters pairs = new HashMap<>(); for (int i = 0; i < clusters.size() - 1; ++i) { HashMap<Cluster, Cluster> map = new HashMap<>(); MergeAction merge = new MergeAction(clusters, i, i + 1, map); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(merge); Cluster clusterI = clusters.get(i); pairs.put(clusterI, map); System.out.printf("Cluster %d paired\n", i); } }
From source file:com.kegare.caveworld.world.WorldProviderDeepCaveworld.java
public static void regenerate(final boolean backup) { final File dir = getDimDir(); final String name = dir.getName().substring(4); final MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); Set<EntityPlayerMP> target = Sets.newHashSet(); for (Object obj : server.getConfigurationManager().playerEntityList.toArray()) { if (obj != null && ((EntityPlayerMP) obj).dimension == CaveworldAPI.getDeepDimension()) { target.add(CaveUtils.respawnPlayer((EntityPlayerMP) obj, 0)); }//from w ww. ja v a 2 s . c om } boolean result = new ForkJoinPool().invoke(new RecursiveTask<Boolean>() { @Override protected Boolean compute() { IChatComponent component; try { component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.regenerating", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); if (server.isSinglePlayer()) { Caveworld.network.sendToAll(new RegenerateMessage(backup)); } Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(0)); CaveBlocks.caveworld_portal.portalDisabled = true; int dim = CaveworldAPI.getDeepDimension(); WorldServer world = DimensionManager.getWorld(dim); if (world != null) { world.saveAllChunks(true, null); world.flush(); MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(world)); DimensionManager.setWorld(dim, null); } if (dir != null) { if (backup) { File parent = dir.getParentFile(); final Pattern pattern = Pattern.compile("^" + dir.getName() + "_bak-..*\\.zip$"); File[] files = parent.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return pattern.matcher(name).matches(); } }); if (files != null && files.length >= 5) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { int i = CaveUtils.compareWithNull(o1, o2); if (i == 0 && o1 != null && o2 != null) { try { i = Files.getLastModifiedTime(o1.toPath()) .compareTo(Files.getLastModifiedTime(o2.toPath())); } catch (IOException e) { } } return i; } }); FileUtils.forceDelete(files[0]); } Calendar calendar = Calendar.getInstance(); String year = Integer.toString(calendar.get(Calendar.YEAR)); String month = String.format("%02d", calendar.get(Calendar.MONTH) + 1); String day = String.format("%02d", calendar.get(Calendar.DATE)); String hour = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)); String minute = String.format("%02d", calendar.get(Calendar.MINUTE)); String second = String.format("%02d", calendar.get(Calendar.SECOND)); File bak = new File(parent, dir.getName() + "_bak-" + Joiner.on("").join(year, month, day) + "-" + Joiner.on("").join(hour, minute, second) + ".zip"); if (bak.exists()) { FileUtils.deleteQuietly(bak); } component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backingup", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(1)); if (CaveUtils.archiveDirZip(dir, bak)) { ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_FILE, FilenameUtils.normalize(bak.getParentFile().getPath())); component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backedup", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true) .setChatClickEvent(click); server.getConfigurationManager().sendChatMsg(component); } else { component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backup.failed", name)); component.getChatStyle().setColor(EnumChatFormatting.RED).setItalic(true); server.getConfigurationManager().sendChatMsg(component); } } FileUtils.deleteDirectory(dir); } if (DimensionManager.shouldLoadSpawn(dim)) { DimensionManager.initDimension(dim); world = DimensionManager.getWorld(dim); if (world != null) { world.saveAllChunks(true, null); world.flush(); } } CaveBlocks.caveworld_portal.portalDisabled = false; component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.regenerated", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(2)); return true; } catch (Exception e) { component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.failed", name)); component.getChatStyle().setColor(EnumChatFormatting.RED).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(3)); CaveLog.log(Level.ERROR, e, component.getUnformattedText()); } return false; } }); if (result && (Config.hardcore || Config.caveborn)) { for (EntityPlayerMP player : target) { if (!CaveworldAPI.isEntityInCaveworld(player)) { CaveUtils.forceTeleport(player, CaveworldAPI.getDeepDimension()); } } } }
From source file:com.chingo247.structureapi.plan.io.StructurePlanReader.java
public List<IStructurePlan> readDirectory(File structurePlanDirectory) { return readDirectory(structurePlanDirectory, false, new ForkJoinPool()); }