Skip to main content



      Home
Home » Modeling » EMF » I don't understand TransactionalEditingDomain.runExclusive
I don't understand TransactionalEditingDomain.runExclusive [message #1701110] Thu, 09 July 2015 07:54 Go to next message
Eclipse UserFriend
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();


Re: I don't understand TransactionalEditingDomain.runExclusive [message #1701121 is a reply to message #1701110] Thu, 09 July 2015 09:07 Go to previous messageGo to next message
Eclipse UserFriend
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();
Re: I don't understand TransactionalEditingDomain.runExclusive [message #1701147 is a reply to message #1701121] Thu, 09 July 2015 10:09 Go to previous message
Eclipse UserFriend
I see. No, I was running it as a simple JUnit test. Indeed executing the code in a running Eclipse instance I get:

t1: Running exclusive start
t1: Running exclusive end
t2: Running exclusive start
t2: Running exclusive end
Previous Topic:How to extends the copy/paste command ?
Next Topic:[CDO] Finding commits matching specific predicate
Goto Forum:
  


Current Time: Sun Jul 13 16:57:38 EDT 2025

Powered by FUDForum. Page generated in 0.66054 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top