Skip to content

Instantly share code, notes, and snippets.

@yamanyar
Created September 24, 2013 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamanyar/6681126 to your computer and use it in GitHub Desktop.
Save yamanyar/6681126 to your computer and use it in GitHub Desktop.
@Override
public void run() {
ExecutorService executorService = Executors.newFixedThreadPool(10);
while (true) {
final long start = System.currentTimeMillis();
for (final AsyncContext aync : rateWatchers) {
executorService.submit(new Runnable() {
@Override
public void run() {
try {
PrintWriter writer = aync.getResponse().getWriter();
writer.println("Time: " + start);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
long timePassed = System.currentTimeMillis() - start;
if (timePassed < 1000) try {
Thread.sleep(1000-timePassed);
} catch (InterruptedException e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment