mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 12:14:47 +00:00
HHH-3628 - Hilo optimizer problem in case of multiple threads accessing the sequence table
- replace the Semaphore with two CountDownLatches that shouldd deliver a more predictable outcome
This commit is contained in:
parent
eef8a48ce4
commit
1aed1b50f7
@ -10,6 +10,7 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -52,7 +53,7 @@ public class HiloOptimizerConcurrencyTest extends BaseNonConfigCoreFunctionalTes
|
|||||||
|
|
||||||
private boolean createSchema = true;
|
private boolean createSchema = true;
|
||||||
|
|
||||||
private ExecutorService executor = Executors.newFixedThreadPool( 2);
|
private ExecutorService executor = Executors.newFixedThreadPool( 2 );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
@ -95,7 +96,8 @@ public void testTwoSessionsParallelGeneration() {
|
|||||||
|
|
||||||
final List<Throwable> errs = new CopyOnWriteArrayList<>();
|
final List<Throwable> errs = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
final Semaphore semaphore = new Semaphore( 0, true );
|
CountDownLatch firstLatch = new CountDownLatch( 1 );
|
||||||
|
CountDownLatch secondLatch = new CountDownLatch( 1 );
|
||||||
|
|
||||||
Callable<Void> callable1 = () -> {
|
Callable<Void> callable1 = () -> {
|
||||||
try {
|
try {
|
||||||
@ -109,8 +111,8 @@ public void testTwoSessionsParallelGeneration() {
|
|||||||
session1.getTransaction().commit();
|
session1.getTransaction().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
semaphore.release();
|
firstLatch.countDown();
|
||||||
semaphore.acquire();
|
secondLatch.await();
|
||||||
try {
|
try {
|
||||||
session1.beginTransaction();
|
session1.beginTransaction();
|
||||||
HibPerson p = new HibPerson();
|
HibPerson p = new HibPerson();
|
||||||
@ -129,7 +131,8 @@ public void testTwoSessionsParallelGeneration() {
|
|||||||
|
|
||||||
Callable<Void> callable2 = () -> {
|
Callable<Void> callable2 = () -> {
|
||||||
try {
|
try {
|
||||||
semaphore.acquire();
|
firstLatch.await();
|
||||||
|
secondLatch.countDown();
|
||||||
try {
|
try {
|
||||||
session2.beginTransaction();
|
session2.beginTransaction();
|
||||||
HibPerson p = new HibPerson();
|
HibPerson p = new HibPerson();
|
||||||
@ -142,23 +145,21 @@ public void testTwoSessionsParallelGeneration() {
|
|||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
errs.add( t );
|
errs.add( t );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
semaphore.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
executor.invokeAll( Arrays.asList(
|
executor.invokeAll( Arrays.asList(
|
||||||
callable1, callable2
|
callable1, callable2
|
||||||
) ).forEach( c -> {
|
) , 30, TimeUnit.SECONDS).forEach( c -> {
|
||||||
try {
|
try {
|
||||||
c.get();
|
c.get();
|
||||||
}
|
}
|
||||||
catch (InterruptedException|ExecutionException e) {
|
catch (InterruptedException|ExecutionException e) {
|
||||||
|
Thread.interrupted();
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
|
|
||||||
for(Throwable ex : errs) {
|
for(Throwable ex : errs) {
|
||||||
fail(ex.getMessage());
|
fail(ex.getMessage());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user