use of java.util.concurrent.ScheduledThreadPoolExecutor in project languagetool by languagetool-org.
the class LanguageToolSupport method init.
private void init() {
try {
config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null);
} catch (IOException ex) {
throw new RuntimeException("Could not load configuration", ex);
}
Language defaultLanguage = config.getLanguage();
if (defaultLanguage == null) {
defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault());
}
/**
* Warm-up: we have a lot of lazy init in LT, which causes the first check to
* be very slow (several seconds) for languages with a lot of data and a lot of
* rules. We just assume that the default language is the language that the user
* often uses and init the LT object for that now, not just when it's first used.
* This makes the first check feel much faster:
*/
reloadLanguageTool(defaultLanguage);
checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
t.setPriority(Thread.MIN_PRIORITY);
t.setName(t.getName() + "-lt-background");
return t;
}
});
check = new AtomicInteger(0);
this.textComponent.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
mustDetectLanguage = config.getAutoDetect();
recalculateSpans(e.getOffset(), e.getLength(), false);
if (backgroundCheckEnabled) {
checkDelayed(null);
}
}
@Override
public void removeUpdate(DocumentEvent e) {
mustDetectLanguage = config.getAutoDetect();
recalculateSpans(e.getOffset(), e.getLength(), true);
if (backgroundCheckEnabled) {
checkDelayed(null);
}
}
@Override
public void changedUpdate(DocumentEvent e) {
mustDetectLanguage = config.getAutoDetect();
if (backgroundCheckEnabled) {
checkDelayed(null);
}
}
});
mouseListener = new MouseListener() {
@Override
public void mouseClicked(MouseEvent me) {
}
@Override
public void mousePressed(MouseEvent me) {
if (me.isPopupTrigger()) {
showPopup(me);
}
}
@Override
public void mouseReleased(MouseEvent me) {
if (me.isPopupTrigger()) {
showPopup(me);
}
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
};
this.textComponent.addMouseListener(mouseListener);
actionListener = e -> _actionPerformed(e);
mustDetectLanguage = config.getAutoDetect();
if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) {
checkImmediately(null);
}
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.
the class TestNonAggregatingLogHandler method testDelayedDelete.
@Test
public void testDelayedDelete() throws IOException {
File[] localLogDirs = getLocalLogDirFiles(this.getClass().getName(), 2);
String localLogDirsString = localLogDirs[0].getAbsolutePath() + "," + localLogDirs[1].getAbsolutePath();
conf.set(YarnConfiguration.NM_LOG_DIRS, localLogDirsString);
conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, false);
conf.setLong(YarnConfiguration.NM_LOG_RETAIN_SECONDS, YarnConfiguration.DEFAULT_NM_LOG_RETAIN_SECONDS);
dirsHandler.init(conf);
NonAggregatingLogHandler logHandler = new NonAggregatingLogHandlerWithMockExecutor(dispatcher, mockDelService, dirsHandler);
logHandler.init(conf);
logHandler.start();
logHandler.handle(new LogHandlerAppStartedEvent(appId, user, null, null));
logHandler.handle(new LogHandlerContainerFinishedEvent(container11, 0));
logHandler.handle(new LogHandlerAppFinishedEvent(appId));
Path[] localAppLogDirs = new Path[2];
localAppLogDirs[0] = new Path(localLogDirs[0].getAbsolutePath(), appId.toString());
localAppLogDirs[1] = new Path(localLogDirs[1].getAbsolutePath(), appId.toString());
ScheduledThreadPoolExecutor mockSched = ((NonAggregatingLogHandlerWithMockExecutor) logHandler).mockSched;
verify(mockSched).schedule(any(Runnable.class), eq(10800l), eq(TimeUnit.SECONDS));
logHandler.close();
for (int i = 0; i < localLogDirs.length; i++) {
FileUtils.deleteDirectory(localLogDirs[i]);
}
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.
the class AppLevelTimelineCollector method serviceStart.
@Override
protected void serviceStart() throws Exception {
// Launch the aggregation thread
appAggregationExecutor = new ScheduledThreadPoolExecutor(AppLevelTimelineCollector.AGGREGATION_EXECUTOR_NUM_THREADS, new ThreadFactoryBuilder().setNameFormat("TimelineCollector Aggregation thread #%d").build());
appAggregator = new AppLevelAggregator();
appAggregationExecutor.scheduleAtFixedRate(appAggregator, AppLevelTimelineCollector.AGGREGATION_EXECUTOR_EXEC_INTERVAL_SECS, AppLevelTimelineCollector.AGGREGATION_EXECUTOR_EXEC_INTERVAL_SECS, TimeUnit.SECONDS);
super.serviceStart();
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.
the class AbstractReservationSystem method startPlanFollower.
private void startPlanFollower(long initialDelay) {
if (planFollower != null) {
scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
scheduledExecutorService.scheduleWithFixedDelay(planFollower, initialDelay, planStepSize, TimeUnit.MILLISECONDS);
}
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project flink by apache.
the class StackTraceSampleCoordinatorTest method testTriggerStackTraceSampleTimeout.
/** Tests that samples time out if they don't finish in time. */
@Test(timeout = 1000L)
public void testTriggerStackTraceSampleTimeout() throws Exception {
int timeout = 100;
coord = new StackTraceSampleCoordinator(system.dispatcher(), timeout);
final ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
try {
ExecutionVertex[] vertices = new ExecutionVertex[] { mockExecutionVertexWithTimeout(new ExecutionAttemptID(), ExecutionState.RUNNING, scheduledExecutorService, timeout) };
Future<StackTraceSample> sampleFuture = coord.triggerStackTraceSample(vertices, 1, Time.milliseconds(100L), 0);
// Wait for the timeout
Thread.sleep(timeout * 2);
boolean success = false;
for (int i = 0; i < 10; i++) {
if (sampleFuture.isDone()) {
success = true;
break;
}
Thread.sleep(timeout);
}
assertTrue("Sample did not time out", success);
try {
sampleFuture.get();
fail("Expected exception.");
} catch (ExecutionException e) {
assertTrue(e.getCause().getCause().getMessage().contains("Timeout"));
}
// Collect after the timeout (should be ignored)
ExecutionAttemptID executionId = vertices[0].getCurrentExecutionAttempt().getAttemptId();
coord.collectStackTraces(0, executionId, new ArrayList<StackTraceElement[]>());
} finally {
scheduledExecutorService.shutdownNow();
}
}
Aggregations