小编Chr*_*lom的帖子

如何衡量执行一段代码的线程数?

我试图测量有多少线程同时执行一段代码.目前我(ab)使用信号量,有更好的方法吗?

final int MAX_THREADS = Integer.MAX_VALUE;

Semaphore s = new Semaphore(MAX_THREADS);

s.acquire(); // start of section

// do some computations

// track how many threads are running the section
trackThreads( (MAX_THREADS - s.availablePermits()) );         

s.release(); // end of section
Run Code Online (Sandbox Code Playgroud)

java concurrency monitoring multithreading semaphore

7
推荐指数
2
解决办法
114
查看次数