博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
线程池执行线程任务花费的时间
阅读量:4230 次
发布时间:2019-05-26

本文共 1101 字,大约阅读时间需要 3 分钟。

public class CounterPoolExecutor extends ThreadPoolExecutor {
private AtomicInteger count = new AtomicInteger(0);//统计执行次数 private long startTime = System.currentTimeMillis(); private String funcname = ""; private final static int COUNT = 100; public CounterPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue
workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } @Override protected void afterExecute(Runnable r, Throwable t) {
//线程执行结束时 int l = count.addAndGet(1); if (l == COUNT) { System.out.println(funcname + "spend time:" + (System.currentTimeMillis() - startTime)); } } public static void main(String[] args) { ExecutorService executorService = new CounterPoolExecutor(50, 100, 60L, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); for (int i = 0; i < 100; i++) { executorService.execute(() -> System.out.print("1")); } }}

转载地址:http://gqjqi.baihongyu.com/

你可能感兴趣的文章
C++ GUI Programming with Qt 4
查看>>
Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications
查看>>
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
查看>>
Moodle E-learning Course Development
查看>>
VoIP For Dummies
查看>>
Administrator's Guide to SQL Server 2005
查看>>
Ajax Design Patterns
查看>>
DNS and BIND (5th Edition)
查看>>
Firewall Fundamentals
查看>>
Learning PHP and MySQL
查看>>
Agile Software Construction
查看>>
Computer Security Basics
查看>>
Sams Teach Yourself MySQL in 10 Minutes
查看>>
Information Systems : The State of the Field
查看>>
IPv6 Essentials
查看>>
Microsoft Visual C++ 2005 Express Edition Programming for the Absolute Beginner
查看>>
Microsoft Visual Basic 2005 Express Edition Programming for the Absolute Beginner
查看>>
Pro .NET 2.0 Windows Forms and Custom Controls in C#
查看>>
Beginning Regular Expressions
查看>>
Beginning Visual Web Developer 2005 Express: From Novice to Professional
查看>>