62,615
社区成员
发帖
与我相关
我的任务
分享
class TravelThread extends Thread
{
/////////////////////这个地方改成了非static
private final AtomicInteger ThreadCount = new AtomicInteger();
private String channel;
public TravelThread(String channel)
{
////////////////////////////这个地方要求我改成static
super("travel-file-thread-" + ThreadCount.incrementAndGet());
this.channel = channel;
}
public void run()
{
try
{
writeresult(channel);
}
catch (Throwable e)
{
onException(e, channel);
}
// System.out.println("threadover is .");
}
public class AtomicInteger extends Number implements java.io.Serializable {
private static final long serialVersionUID = 6214790243416807050L;
// setup to use Unsafe.compareAndSwapInt for updates
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final long valueOffset;
static {
try {
valueOffset = unsafe.objectFieldOffset
(AtomicInteger.class.getDeclaredField("value"));
} catch (Exception ex) { throw new Error(ex); }
}
private volatile int value;
public AtomicInteger() {
}
public final int incrementAndGet() {
return unsafe.getAndAddInt(this, valueOffset, 1) + 1;
}