Added tests for thread-pool pattern

Fixed concurrency problem in id generation of Task
This commit is contained in:
Jeroen Meulemeester
2015-12-30 19:49:47 +01:00
parent 47709e24b9
commit fd8c05846f
8 changed files with 198 additions and 5 deletions

View File

@@ -1,19 +1,21 @@
package com.iluwatar.threadpool;
import java.util.concurrent.atomic.AtomicInteger;
/**
*
*
* Abstract base class for tasks
*
*/
public abstract class Task {
private static int nextId = 1;
private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
private final int id;
private final int timeMs;
public Task(final int timeMs) {
this.id = nextId++;
this.id = ID_GENERATOR.incrementAndGet();
this.timeMs = timeMs;
}