blob: 23278641b71e157379694c0342eda30637b66c6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* https://github.com/eclipse-aspectj/aspectj/issues/279
*/
public class Application {
public static AtomicInteger HELLO_COUNT = new AtomicInteger(0);
public static AtomicInteger ASPECT_COUNT = new AtomicInteger(0);
private static final int ROUNDS = 25;
private static final int THREAD_COUNT = 2;
private static final int TOTAL_COUNT = ROUNDS * THREAD_COUNT;
private static final String CLASS_TO_LOAD = "GreeterImpl";
public static void main(String[] args) throws Exception {
for (int round = 0; round < ROUNDS; round++) {
ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
ParallelCapableClassLoader cl = new ParallelCapableClassLoader(Application.class.getClassLoader(), CLASS_TO_LOAD);
for (int i = 0; i < THREAD_COUNT; i++) {
executor.submit(() -> {
try {
Class<?> myClass = Class.forName(CLASS_TO_LOAD, true, cl);
Greeter greeter = (Greeter) myClass.getConstructor(new Class<?>[] {}).newInstance();
greeter.hello();
HELLO_COUNT.incrementAndGet();
}
catch (Exception e) {
throw new RuntimeException(e);
}
});
}
executor.shutdown();
executor.awaitTermination(60, TimeUnit.SECONDS);
}
assert HELLO_COUNT.get() == TOTAL_COUNT
: String.format("Hello count should be %s, but is %s", TOTAL_COUNT, HELLO_COUNT.get());
assert ASPECT_COUNT.get() == TOTAL_COUNT
: String.format("Aspect count should be %s, but is %s", TOTAL_COUNT, ASPECT_COUNT.get());
}
}
|