<pre name="code" class="html">SubThread sc = new SubThread();
//n为指定线程数
public void fun(Thread t) {
synchronized (SubThread.class) {
//获取线程个数
int count = SubThread.getThreadCounts();
while (count >= n) {
try {
sc.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
sc.notifyAll();
}
<pre name="code" class="html">SubThread sc = new SubThread();
//n为指定线程数
public void fun(Thread t) {
synchronized (SubThread.class) {
//获取线程个数
int count = SubThread.getThreadCounts();
while (count >= n) {
try {
sc.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
sc.notifyAll();
}