I don't understand TransactionalEditingDomain.runExclusive [message #1701110] |
Thu, 09 July 2015 07:54  |
Eclipse User |
|
|
|
Hi.
Reading the documentation of runExclusive I thought when two runnables from different threads access the editing domain they both run exclusively. However this seems not to be the case.
If I run the following code I get the output:
t1: Running exclusive start
t2: Running exclusive start
t2: Running exclusive end
t1: Running exclusive end
What am I doing wrong?
Code:
EClass model = EcoreFactory.eINSTANCE.createEClass();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = new ResourceImpl();
resource.setURI(URI.createURI("synthetic://model"));
resourceSet.getResources().add(resource);
resource.getContents().add(model);
TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(model);
Thread t1 = new Thread(() -> {
try {
TransactionUtil.getEditingDomain(model).runExclusive(() -> {
System.out.println((Thread.currentThread().getName() + ": Running exclusive start"));
try {
Thread.sleep(2000l);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + ": Running exclusive end");
});
} catch (Exception e) {
e.printStackTrace();
}
});
t1.setName("t1");
Thread t2 = new Thread(() -> {
try {
domain.runExclusive(() -> {
System.out.println(Thread.currentThread().getName() + ": Running exclusive start");
System.out.println(Thread.currentThread().getName() + ": Running exclusive end");
});
} catch (Exception e) {
e.printStackTrace();
}
});
t2.setName("t2");
t1.start();
Thread.sleep(1000);
t2.start();
t1.join();
t2.join();
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.66054 seconds