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);
}
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());
}
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()));
}
}
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());
}
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;
}
Aggregations