use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.
the class GlobalMonitor method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
nThreads = nThreads <= 0 ? DEFAULT_THREADS : nThreads;
executor = new ThreadPoolExecutor(nThreads, nThreads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(nThreads * 2), new NamedThreadFactory("global monitor", false), new ThreadPoolExecutor.CallerRunsPolicy());
}
use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.
the class OtterDownStreamHandler method startDetecting.
private void startDetecting() {
// 直接发送已追上的状态,保持和eromanga兼容处理
MainStemEventData mainStemData = new MainStemEventData();
mainStemData.setPipelineId(pipelineId);
mainStemData.setStatus(MainStemEventData.Status.OVERTAKE);
arbitrateEventService.mainStemEvent().single(mainStemData);
// 启动异步线程定时监控,一定会有数据过来
String schedulerName = String.format("pipelineId = %s , CanalDetecting", String.valueOf(pipelineId));
scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(schedulerName));
future = scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
// (因为会有心跳包数据,理论上时间间隔会小于一定值)
if (isDelayed(System.currentTimeMillis(), lastEventExecuteTime)) {
notifyFailed();
} else {
notifySuccessed();
}
} catch (Exception e) {
logger.error("heartbeat check failed!", e);
} finally {
MDC.remove(OtterConstants.splitPipelineLogFileKey);
}
}
}, detectingIntervalInSeconds, detectingIntervalInSeconds, TimeUnit.SECONDS);
}
use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.
the class StatisticsClientServiceImpl method afterPropertiesSet.
// ================= helper method ==============
public void afterPropertiesSet() throws Exception {
scheduler = new ScheduledThreadPoolExecutor(DEFAULT_POOL, new NamedThreadFactory("Otter-Statistics-Client"), new ThreadPoolExecutor.CallerRunsPolicy());
scheduler.submit(new Runnable() {
public void run() {
doSendDelayCountEvent();
}
});
}
use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.
the class DbPerfIntergration method test_stack.
@Test
public void test_stack() {
DbMediaSource dbMediaSource = new DbMediaSource();
dbMediaSource.setId(1L);
dbMediaSource.setDriver("com.mysql.jdbc.Driver");
dbMediaSource.setUsername("otter");
dbMediaSource.setPassword("otter");
dbMediaSource.setUrl("jdbc:mysql://127.0.0.1:3306/retl");
dbMediaSource.setEncode("UTF-8");
dbMediaSource.setType(DataMediaType.MYSQL);
DbDataMedia dataMedia = new DbDataMedia();
dataMedia.setSource(dbMediaSource);
dataMedia.setId(1L);
dataMedia.setName("ljhtable1");
dataMedia.setNamespace("otter");
final DbDialect dbDialect = dbDialectFactory.getDbDialect(2L, dataMedia.getSource());
want.object(dbDialect).clazIs(MysqlDialect.class);
final TransactionTemplate transactionTemplate = dbDialect.getTransactionTemplate();
// 插入数据准备
int minute = 5;
int nextId = 1;
final int thread = 10;
final int batch = 50;
final String sql = "insert into otter.ljhtable1 values(? , ? , ? , ?)";
final CountDownLatch latch = new CountDownLatch(thread);
ExecutorService executor = new ThreadPoolExecutor(thread, thread, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(thread * 2), new NamedThreadFactory("load"), new ThreadPoolExecutor.CallerRunsPolicy());
for (int sec = 0; sec < minute * 60; sec++) {
// 执行秒循环
long startTime = System.currentTimeMillis();
for (int i = 0; i < thread; i++) {
final int start = nextId + i * batch;
executor.submit(new Runnable() {
public void run() {
try {
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
JdbcTemplate jdbcTemplate = dbDialect.getJdbcTemplate();
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int idx) throws SQLException {
int id = start + idx;
StatementCreatorUtils.setParameterValue(ps, 1, Types.INTEGER, null, id);
StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, null, RandomStringUtils.randomAlphabetic(1000));
// RandomStringUtils.randomAlphabetic()
long time = new Date().getTime();
StatementCreatorUtils.setParameterValue(ps, 3, Types.TIMESTAMP, new Timestamp(time));
StatementCreatorUtils.setParameterValue(ps, 4, Types.TIMESTAMP, new Timestamp(time));
}
public int getBatchSize() {
return batch;
}
});
}
});
} finally {
latch.countDown();
}
}
});
}
long endTime = System.currentTimeMillis();
try {
latch.await(1000 * 60L - (endTime - startTime), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (latch.getCount() != 0) {
System.out.println("perf is not enough!");
System.exit(-1);
}
endTime = System.currentTimeMillis();
System.out.println("Time cost : " + (System.currentTimeMillis() - startTime));
try {
TimeUnit.MILLISECONDS.sleep(1000L - (endTime - startTime));
} catch (InterruptedException e) {
e.printStackTrace();
}
nextId = nextId + thread * batch;
}
executor.shutdown();
}
use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.
the class DefaultCommunicationClientImpl method initial.
public void initial() {
RejectedExecutionHandler handler = null;
if (discard) {
handler = new ThreadPoolExecutor.DiscardPolicy();
} else {
handler = new ThreadPoolExecutor.AbortPolicy();
}
executor = new ThreadPoolExecutor(poolSize, poolSize, 60 * 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(10 * 1000), new NamedThreadFactory("communication-async"), handler);
}
Aggregations