package thread.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadTest implements Runnable
{
public static void main(String[] args)
{
for (int i = 0; i < sfThreadNum; i++)
{
new Thread(new ThreadTest()).start();
;
}
try
{
sfAllTaskLatch.await();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
/*for (int num : set)
{
System.out.println(num);
}
System.out.println("大小" + set.size());*/
}
@Override
public void run()
{
// mStartIndex = safe.getAndIncrement();
//以原子的方式实现加1
mStartIndex = sTaskIndex.getAndIncrement();
synchronized (set)
{
set.add(mStartIndex);
}
try
{
Thread.sleep(1000);
System.out.printf("线程%3d启动!!!", mStartIndex);
System.out.println();
}
c
AtomicInteger、CountDownLatch并发编程
最新推荐文章于 2022-06-14 15:48:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)