|
Re: I don't understand TransactionalEditingDomain.runExclusive [message #1701121 is a reply to message #1701110] |
Thu, 09 July 2015 13:07 |
|
Hi,
Are you running this code in a running Eclipse instance, with the Job
Manager enabled (not in its suspended state)? The transaction lock is
implemented using the Job Manager's locking system, which supports
deadlock detection.
Cheers,
Christian
On 2015-07-09 11:54:24 +0000, Nils Ruhr said:
> 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.25850 seconds