Java Code Examples for java.util.concurrent.ForkJoinWorkerThread#setName()

The following examples show how to use java.util.concurrent.ForkJoinWorkerThread#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoadServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
ExecutorService getExecutor(int asyncThreads) {
  // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
  // put.  Move it somewhere else, or remove it if no longer necessary.
  // See: https://github.com/grpc/grpc-java/issues/2119
  return new ForkJoinPool(asyncThreads,
      new ForkJoinWorkerThreadFactory() {
        final AtomicInteger num = new AtomicInteger();
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
          ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
          thread.setDaemon(true);
          thread.setName("server-worker-" + "-" + num.getAndIncrement());
          return thread;
        }
      }, UncaughtExceptionHandlers.systemExit(), true /* async */);
}
 
Example 2
Source File: LoadServer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
ExecutorService getExecutor(int asyncThreads) {
  // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
  // put.  Move it somewhere else, or remove it if no longer necessary.
  // See: https://github.com/grpc/grpc-java/issues/2119
  return new ForkJoinPool(asyncThreads,
      new ForkJoinWorkerThreadFactory() {
        final AtomicInteger num = new AtomicInteger();
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
          ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
          thread.setDaemon(true);
          thread.setName("server-worker-" + "-" + num.getAndIncrement());
          return thread;
        }
      }, UncaughtExceptionHandlers.systemExit(), true /* async */);
}
 
Example 3
Source File: MediaScannerService.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
    final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
    worker.setName("MediaLibraryScanner-" + worker.getPoolIndex());
    worker.setPriority(Thread.MIN_PRIORITY);
    return worker;
}
 
Example 4
Source File: InMemCubeBuilder2.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Build all the cuboids and wait for all the tasks finished. 
 * 
 * @param input
 * @param listener
 * @return
 * @throws IOException
 */
private <T> NavigableMap<Long, CuboidResult> buildAndCollect(final RecordConsumeBlockingQueueController<T> input,
        final ICuboidResultListener listener) throws IOException {

    long startTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 start, {}", cubeDesc.getName());

    // build base cuboid
    buildBaseCuboid(input, listener);

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("inmem-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };
    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    ForkJoinTask rootTask = builderPool.submit(new Runnable() {
        @Override
        public void run() {
            startBuildFromBaseCuboid();
        }
    });
    rootTask.join();

    long endTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 end, {}, takes {} ms", cubeDesc.getName(), (endTime - startTime));
    logger.info("total CuboidResult count: {}", resultCollector.getAllResult().size());
    return resultCollector.getAllResult();
}
 
Example 5
Source File: ExecutorFactory.java    From botbuilder-java with MIT License 5 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
    ForkJoinWorkerThread worker =
        ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
    worker.setName("Bot-" + worker.getPoolIndex());
    return worker;
}
 
Example 6
Source File: ForkJoinPoolExecutorFactory.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
    // Note: The ForkJoinPool will create these threads as daemon threads.
    ForkJoinWorkerThread thread = new InternalForkJoinWorkerThread(pool);
    thread.setName(namePrefix + '-' + idx.getAndIncrement());
    return thread;
}
 
Example 7
Source File: InMemCubeBuilder2.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Build all the cuboids and wait for all the tasks finished. 
 * 
 * @param input
 * @param listener
 * @return
 * @throws IOException
 */
private <T> NavigableMap<Long, CuboidResult> buildAndCollect(final RecordConsumeBlockingQueueController<T> input,
        final ICuboidResultListener listener) throws IOException {

    long startTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 start, {}", cubeDesc.getName());

    // build base cuboid
    buildBaseCuboid(input, listener);

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("inmem-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };
    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    ForkJoinTask rootTask = builderPool.submit(new Runnable() {
        @Override
        public void run() {
            startBuildFromBaseCuboid();
        }
    });
    rootTask.join();

    long endTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 end, {}, takes {} ms", cubeDesc.getName(), (endTime - startTime));
    logger.info("total CuboidResult count: {}", resultCollector.getAllResult().size());
    return resultCollector.getAllResult();
}
 
Example 8
Source File: IdeaForkJoinWorkerThreadFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
  final int n = setNextBit();
  ForkJoinWorkerThread thread = new ForkJoinWorkerThread(pool) {
    @Override
    protected void onTermination(Throwable exception) {
      clearBit(n);
      super.onTermination(exception);
    }
  };
  thread.setName("JobScheduler FJ pool " + n + "/" + PARALLELISM);
  thread.setPriority(Thread.NORM_PRIORITY - 1);
  return thread;
}
 
Example 9
Source File: DoggedCubeBuilder2.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public <T> void build(BlockingQueue<T> input, InputConverterUnit<T> inputConverterUnit, ICuboidWriter output)
        throws IOException {
    final RecordConsumeBlockingQueueController<T> inputController = RecordConsumeBlockingQueueController
            .getQueueController(inputConverterUnit, input);

    final List<InMemCubeBuilder2> builderList = new CopyOnWriteArrayList<>();

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("dogged-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };

    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    CuboidResultWatcher resultWatcher = new CuboidResultWatcher(builderList, output);

    Stopwatch sw = new Stopwatch();
    sw.start();
    logger.info("Dogged Cube Build2 start");
    try {
        BaseCuboidTask<T> task = new BaseCuboidTask<>(inputController, 1, resultWatcher);
        builderPool.execute(task);
        do {
            builderList.add(task.getInternalBuilder());
            //Exception will be thrown here if cube building failure
            task.join();
            task = task.nextTask();
        } while (task != null);

        logger.info("Has finished feeding data, and base cuboid built, start to build child cuboids");
        for (final InMemCubeBuilder2 builder : builderList) {
            builderPool.submit(new Runnable() {
                @Override
                public void run() {
                    builder.startBuildFromBaseCuboid();
                }
            });
        }
        resultWatcher.start();
        logger.info("Dogged Cube Build2 splits complete, took " + sw.elapsedMillis() + " ms");
    } catch (Throwable e) {
        logger.error("Dogged Cube Build2 error", e);
        if (e instanceof Error)
            throw (Error) e;
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new IOException(e);
    } finally {
        output.close();
        closeGirdTables(builderList);
        sw.stop();
        builderPool.shutdownNow();
        logger.info("Dogged Cube Build2 end, totally took " + sw.elapsedMillis() + " ms");
        logger.info("Dogged Cube Build2 return");
    }
}
 
Example 10
Source File: HdfsTestUtil.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
  ForkJoinWorkerThread worker = new SecurityManagerWorkerThread(pool);
  worker.setName("solr-hdfs-threadpool-" + worker.getPoolIndex());
  return worker;
}
 
Example 11
Source File: TestBaseGenerate.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Test
    public void testPlanExecution() throws Exception {

        String query = IOUtils.toString(sm.open(new LookUpRequest(request.query, SPARQLExt.MEDIA_TYPE)), "UTF-8");

        long start0 = System.currentTimeMillis();
        long start = start0;
        SPARQLExtQuery q = (SPARQLExtQuery) QueryFactory.create(query, SPARQLExt.SYNTAX);
        long now = System.currentTimeMillis();
        log.info("needed " + (now - start) + " to parse query");
        start = now;

        // create generation plan
        RootPlan plan = PlanFactory.create(q);
        Dataset ds = request.loadDataset(exampleDir);

        now = System.currentTimeMillis();
        log.info("needed " + (now - start) + " to get ready");
        start = now;

        // execute plan

        ExecutorService executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
            (ForkJoinPool pool) -> {
                final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
                worker.setName("test-" + name + "-" + worker.getPoolIndex());
                return worker;
            },
            null, true);

        ScheduledExecutorService guard = Executors.newScheduledThreadPool(1);
        guard.schedule(()->{executor.shutdownNow();}, 15, TimeUnit.SECONDS);
        Model output;
        Context context = ContextUtils.build()
                .setPrefixMapping(q)
                .setStreamManager(sm)
                .setExecutor(executor)
                .setInputDataset(ds)
                .build();
        output = plan.execGenerate(context);
        guard.shutdownNow();

        now = System.currentTimeMillis();
        log.info("executed plan in " + (now - start));
        start = now;
        log.info("total needed " + (now - start0));

        // write output
        String fileName = exampleDir.toString() + "/output.ttl";
        FileWriter out = new FileWriter(fileName);
        try {
            output.write(out, "TTL");
            StringWriter sw = new StringWriter();
            output.write(sw, "TTL");
            LOG.debug("output is \n" + sw.toString());
        } finally {
            try {
                out.close();
            } catch (IOException closeException) {
                log.error("Error while writing to file");
            }
        }

        URI expectedOutputUri = exampleDir.toURI().resolve("expected_output.ttl");
        Model expectedOutput = RDFDataMgr.loadModel(expectedOutputUri.toString(), Lang.TTL);
//        StringWriter sw = new StringWriter();
//        expectedOutput.write(System.out, "TTL");
        System.out.println("Is isomorphic: " + output.isIsomorphicWith(expectedOutput));
        if (!output.isIsomorphicWith(expectedOutput)) {
            output.listStatements().forEachRemaining((s) -> {
                if (!expectedOutput.contains(s)) {
                    LOG.debug("expectedOutput does not contain " + s);
                }
                expectedOutput.remove(s);
            });
            expectedOutput.listStatements().forEachRemaining((s) -> {
                LOG.debug("output does not contain " + s);
            });
        }

        assertTrue("Error with test " + exampleDir.getName(), output.isIsomorphicWith(expectedOutput));
    }
 
Example 12
Source File: NexusForkJoinWorkerThreadFactory.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ForkJoinWorkerThread newThread(final ForkJoinPool pool) {
  final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
  worker.setName(jobPrefix + worker.getPoolIndex());
  return worker;
}
 
Example 13
Source File: DoggedCubeBuilder2.java    From kylin with Apache License 2.0 4 votes vote down vote up
public <T> void build(BlockingQueue<T> input, InputConverterUnit<T> inputConverterUnit, ICuboidWriter output)
        throws IOException {
    final RecordConsumeBlockingQueueController<T> inputController = RecordConsumeBlockingQueueController
            .getQueueController(inputConverterUnit, input);

    final List<InMemCubeBuilder2> builderList = new CopyOnWriteArrayList<>();

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("dogged-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };

    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    CuboidResultWatcher resultWatcher = new CuboidResultWatcher(builderList, output);

    Stopwatch sw = Stopwatch.createUnstarted();
    sw.start();
    logger.info("Dogged Cube Build2 start");
    try {
        BaseCuboidTask<T> task = new BaseCuboidTask<>(inputController, 1, resultWatcher);
        builderPool.execute(task);
        do {
            builderList.add(task.getInternalBuilder());
            //Exception will be thrown here if cube building failure
            task.join();
            task = task.nextTask();
        } while (task != null);

        logger.info("Has finished feeding data, and base cuboid built, start to build child cuboids");
        for (final InMemCubeBuilder2 builder : builderList) {
            builderPool.submit(new Runnable() {
                @Override
                public void run() {
                    builder.startBuildFromBaseCuboid();
                }
            });
        }
        resultWatcher.start();
        logger.info("Dogged Cube Build2 splits complete, took " + sw.elapsed(MILLISECONDS) + " ms");
    } catch (Throwable e) {
        logger.error("Dogged Cube Build2 error", e);
        if (e instanceof Error)
            throw (Error) e;
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new IOException(e);
    } finally {
        output.close();
        closeGirdTables(builderList);
        sw.stop();
        builderPool.shutdownNow();
        logger.info("Dogged Cube Build2 end, totally took " + sw.elapsed(MILLISECONDS) + " ms");
        logger.info("Dogged Cube Build2 return");
    }
}