Search in sources :

Example 96 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project hadoop by apache.

the class ApplicationMasterLauncher method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    int threadCount = conf.getInt(YarnConfiguration.RM_AMLAUNCHER_THREAD_COUNT, YarnConfiguration.DEFAULT_RM_AMLAUNCHER_THREAD_COUNT);
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("ApplicationMasterLauncher #%d").build();
    launcherPool = new ThreadPoolExecutor(threadCount, threadCount, 1, TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>());
    launcherPool.setThreadFactory(tf);
    Configuration newConf = new YarnConfiguration(conf);
    newConf.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY, conf.getInt(YarnConfiguration.RM_NODEMANAGER_CONNECT_RETRIES, YarnConfiguration.DEFAULT_RM_NODEMANAGER_CONNECT_RETRIES));
    setConfig(newConf);
    super.serviceInit(newConf);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 97 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project ribbon by Netflix.

the class EurekaNotificationServerListUpdaterTest method setUp.

@Before
public void setUp() {
    eurekaClientMock = setUpEurekaClientMock();
    eurekaClientMock2 = setUpEurekaClientMock();
    // use a test executor so that the tests do not share executors
    testExecutor = new ThreadPoolExecutor(2, 2 * 5, 0, TimeUnit.NANOSECONDS, new ArrayBlockingQueue<Runnable>(1000), new ThreadFactoryBuilder().setNameFormat("EurekaNotificationServerListUpdater-%d").setDaemon(true).build());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Before(org.junit.Before)

Example 98 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project sonarqube by SonarSource.

the class FileIndexer method index.

void index(DefaultModuleFileSystem fileSystem) {
    int threads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1);
    this.executorService = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setNameFormat("FileIndexer-%d").build());
    progressReport = new ProgressReport("Report about progress of file indexation", TimeUnit.SECONDS.toMillis(10));
    progressReport.start("Index files");
    exclusionFilters.prepare();
    Progress progress = new Progress();
    indexFiles(fileSystem, progress, fileSystem.sources(), InputFile.Type.MAIN);
    indexFiles(fileSystem, progress, fileSystem.tests(), InputFile.Type.TEST);
    waitForTasksToComplete();
    progressReport.stop(progress.count() + " " + pluralizeFiles(progress.count()) + " indexed");
    if (exclusionFilters.hasPattern()) {
        LOG.info("{} {} ignored because of inclusion/exclusion patterns", progress.excludedByPatternsCount(), pluralizeFiles(progress.excludedByPatternsCount()));
    }
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ProgressReport(org.sonar.scanner.util.ProgressReport)

Example 99 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project MSEC by Tencent.

the class MysqlSink method start.

@Override
public void start() {
    super.start();
    try {
        //调用Class.forName()方法加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    String url = "jdbc:mysql://" + hostname + ":" + port + "/" + databaseName + "?autoReconnect=true";
    try {
        conn = DriverManager.getConnection(url, user, password);
        conn.setAutoCommit(false);
    } catch (SQLException e) {
        e.printStackTrace();
        System.exit(1);
    }
    pathController.setBaseDirectory(directory);
    rollService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("MysqlSink-roller-" + Thread.currentThread().getId() + "-%d").build());
    /*
       * Every N seconds, mark that it's time to rotate. We purposefully do NOT
       * touch anything other than the indicator flag to avoid error handling
       * issues (e.g. IO exceptions occuring in two different threads.
       * Resist the urge to actually perform rotation in a separate thread!
       */
    rollService.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            LOG.debug("Marking time to rotate file {}", pathController.getCurrentFile());
            shouldRotate = true;
        }
    }, rollInterval, rollInterval, TimeUnit.SECONDS);
    LOG.info("MysqlSink {} started.", getName());
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) String(java.lang.String)

Example 100 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project helios by spotify.

the class EventSenderFactory method build.

public static List<EventSender> build(final Environment environment, final CommonConfiguration<?> config, final MetricRegistry metricRegistry, final String pubsubHealthcheckTopic) {
    final List<EventSender> senders = new ArrayList<>();
    final KafkaClientProvider kafkaClientProvider = new KafkaClientProvider(config.getKafkaBrokers());
    final Optional<KafkaProducer<String, byte[]>> kafkaProducer = kafkaClientProvider.getDefaultProducer();
    kafkaProducer.ifPresent(producer -> senders.add(new KafkaSender(producer)));
    final LifecycleEnvironment lifecycle = environment.lifecycle();
    if (!config.getPubsubPrefixes().isEmpty()) {
        final PubSub pubsub = PubSubOptions.getDefaultInstance().getService();
        final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("pubsub-healthchecker-%d").build());
        // choose an arbitrary prefix to use in the healthcheck. we assume if we can connect to
        // one we can connect to all
        final String topicToHealthcheck = config.getPubsubPrefixes().iterator().next() + pubsubHealthcheckTopic;
        final GooglePubSubSender.DefaultHealthChecker healthchecker = new GooglePubSubSender.DefaultHealthChecker(pubsub, topicToHealthcheck, executor, Duration.ofMinutes(5));
        metricRegistry.register("pubsub-health", (Gauge<Boolean>) healthchecker::isHealthy);
        for (final String prefix : config.getPubsubPrefixes()) {
            final GooglePubSubSender sender = GooglePubSubSender.create(pubsub, prefix, healthchecker);
            senders.add(sender);
        }
        lifecycle.manage(new ManagedPubSub(pubsub));
    }
    senders.forEach(lifecycle::manage);
    return senders;
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) PubSub(com.google.cloud.pubsub.PubSub) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ArrayList(java.util.ArrayList) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)124 ThreadFactory (java.util.concurrent.ThreadFactory)38 ExecutorService (java.util.concurrent.ExecutorService)35 IOException (java.io.IOException)19 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)18 Future (java.util.concurrent.Future)16 ExecutionException (java.util.concurrent.ExecutionException)14 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Callable (java.util.concurrent.Callable)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Path (org.apache.hadoop.fs.Path)9 Test (org.junit.Test)9 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 Before (org.junit.Before)8 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)7 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)7