Created
September 10, 2016 16:14
-
-
Save tuphamphuong/a3dbece574d9d5b3ce9db2a3ebd536f9 to your computer and use it in GitHub Desktop.
Monitor executor service
This file contains hidden or 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
import java.util.concurrent.ThreadPoolExecutor; | |
public class MyMonitorThread implements Runnable | |
{ | |
private ThreadPoolExecutor executor; | |
private int seconds; | |
private boolean run=true; | |
public MyMonitorThread(ThreadPoolExecutor executor, int delay) | |
{ | |
this.executor = executor; | |
this.seconds=delay; | |
} | |
public void shutdown(){ | |
this.run=false; | |
} | |
@Override | |
public void run() | |
{ | |
while(run){ | |
System.out.println( | |
String.format("[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s", | |
this.executor.getPoolSize(), | |
this.executor.getCorePoolSize(), | |
this.executor.getActiveCount(), | |
this.executor.getCompletedTaskCount(), | |
this.executor.getTaskCount(), | |
this.executor.isShutdown(), | |
this.executor.isTerminated())); | |
try { | |
Thread.sleep(seconds*1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment