Created
September 24, 2013 06:44
-
-
Save yamanyar/6681126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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