show active threads in metrics

This commit is contained in:
Athou
2013-07-05 09:52:23 +02:00
parent 5530c5fd7e
commit c388e726fe
4 changed files with 28 additions and 9 deletions

View File

@@ -17,7 +17,8 @@ public class FeedRefreshExecutor {
private ThreadPoolExecutor pool;
private LinkedBlockingDeque<Runnable> queue;
public FeedRefreshExecutor(final String poolName, int threads, int queueCapacity) {
public FeedRefreshExecutor(final String poolName, int threads,
int queueCapacity) {
this.poolName = poolName;
pool = new ThreadPoolExecutor(threads, threads, 0,
TimeUnit.MILLISECONDS,
@@ -46,7 +47,8 @@ public class FeedRefreshExecutor {
queue.put(r);
}
} catch (InterruptedException e1) {
log.error(poolName + " interrupted while waiting for queue.", e1);
log.error(poolName
+ " interrupted while waiting for queue.", e1);
}
}
});
@@ -60,6 +62,10 @@ public class FeedRefreshExecutor {
return queue.size();
}
public int getActiveCount() {
return pool.getActiveCount();
}
public static interface Task extends Runnable {
boolean isUrgent();
}
@@ -70,7 +76,9 @@ public class FeedRefreshExecutor {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
log.error("{} interrupted while waiting for threads to finish.", poolName);
log.error(
"{} interrupted while waiting for threads to finish.",
poolName);
}
}
}

View File

@@ -185,4 +185,8 @@ public class FeedRefreshUpdater {
return pool.getQueueSize();
}
public int getActiveCount() {
return pool.getActiveCount();
}
}

View File

@@ -53,7 +53,8 @@ public class FeedRefreshWorker {
ApplicationSettings settings = applicationSettingsService.get();
int threads = settings.getBackgroundThreads();
log.info("Creating refresh worker pool with {} threads", threads);
pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads, 20 * threads);
pool = new FeedRefreshExecutor("FeedRefreshUpdater", threads,
20 * threads);
}
@PreDestroy
@@ -64,11 +65,15 @@ public class FeedRefreshWorker {
public void updateFeed(Feed feed) {
pool.execute(new FeedTask(feed));
}
public int getQueueSize(){
public int getQueueSize() {
return pool.getQueueSize();
}
public int getActiveCount() {
return pool.getActiveCount();
}
private class FeedTask implements Task {
private Feed feed;
@@ -125,7 +130,8 @@ public class FeedRefreshWorker {
feedRefreshUpdater.updateFeed(feed, entries);
} catch (NotModifiedException e) {
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage());
log.debug("Feed not modified : {} - {}", feed.getUrl(),
e.getMessage());
Date disabledUntil = null;
if (applicationSettingsService.get().isHeavyLoad()) {