cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Álvaro Martínez <alvaro_marti...@ptbsl.com>
Subject Re: Selective commit
Date Tue, 08 Jan 2008 14:05:37 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
Hi, I'm running some issues on this one.<br>
<br>
I now create a new child data context on every situation. But I'm
always getting the same deadlock. I can't figure out how to fix this
from my own code.<br>
<br>
I've googled other people who also had a similar problem, but didn't
help.<br>
<br>
This is the explanation from jConsole:<br>
<br>
<br>
<br>
<small><br>
<br>
Name: Timer-0<br>
State: BLOCKED on org.apache.cayenne.event.DispatchQueue@c25268 owned
by: Timer-4<br>
Total blocked: 3&nbsp; Total waited: 68<br>
<br>
Stack trace: <br>
org.apache.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:54)<br>
org.apache.cayenne.event.EventManager.dispatchEvent(EventManager.java:336)<br>
org.apache.cayenne.event.EventManager.postEvent(EventManager.java:307)<br>
org.apache.cayenne.access.DataContext.fireDataChannelChanged(DataContext.java:1704)<br>
org.apache.cayenne.access.DataContextMergeHandler.graphFlushed(DataContextMergeHandler.java:114)<br>
sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)<br>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
java.lang.reflect.Method.invoke(Method.java:597)<br>
org.apache.cayenne.util.Invocation.fire(Invocation.java:204)<br>
org.apache.cayenne.event.EventManager$Dispatch.fire(EventManager.java:397)<br>
org.apache.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:162)<br>
org.apache.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:58)<br>
&nbsp;&nbsp; - locked org.apache.cayenne.event.DispatchQueue@12d553e<br>
org.apache.cayenne.event.EventManager.dispatchEvent(EventManager.java:336)<br>
org.apache.cayenne.event.EventManager.postEvent(EventManager.java:307)<br>
org.apache.cayenne.access.DataContext.fireDataChannelCommitted(DataContext.java:1680)<br>
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1247)<br>
&nbsp;&nbsp; - locked org.apache.cayenne.access.ObjectStore@137958b<br>
org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1192)<br>
org.apache.cayenne.access.DataContext.onSync(DataContext.java:1167)<br>
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1234)<br>
&nbsp;&nbsp; - locked org.apache.cayenne.access.ObjectStore@1b3a10d<br>
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)<br>
com.ptb.confignode.ConfigNode.newConfigGenerated(ConfigNode.java:711)<br>
&nbsp;&nbsp; - locked java.lang.Boolean@3b13c5<br>
com.ptb.confignode.tasks.GenerateNewDistribution.run(GenerateNewDistribution.java:162)<br>
java.util.TimerThread.mainLoop(Timer.java:512)<br>
java.util.TimerThread.run(Timer.java:462)<br>
<br>
<br>
<br>
<br>
Name: Timer-4<br>
State: BLOCKED on org.apache.cayenne.access.ObjectStore@1b3a10d owned
by: Timer-0<br>
Total blocked: 20&nbsp; Total waited: 799<br>
<br>
Stack trace: <br>
org.apache.cayenne.access.DataContextMergeHandler.graphChanged(DataContextMergeHandler.java:99)<br>
sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)<br>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
java.lang.reflect.Method.invoke(Method.java:597)<br>
org.apache.cayenne.util.Invocation.fire(Invocation.java:204)<br>
org.apache.cayenne.event.EventManager$Dispatch.fire(EventManager.java:397)<br>
org.apache.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:162)<br>
org.apache.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:58)<br>
&nbsp;&nbsp; - locked org.apache.cayenne.event.DispatchQueue@c25268<br>
org.apache.cayenne.event.EventManager.dispatchEvent(EventManager.java:336)<br>
org.apache.cayenne.event.EventManager.postEvent(EventManager.java:307)<br>
org.apache.cayenne.access.DataContext.fireDataChannelChanged(DataContext.java:1704)<br>
org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1189)<br>
org.apache.cayenne.access.DataContext.onSync(DataContext.java:1167)<br>
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1234)<br>
&nbsp;&nbsp; - locked org.apache.cayenne.access.ObjectStore@a86d2f<br>
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)<br>
com.ptb.commons.db.services.StatsServices.addForClient(StatsServices.java:42)<br>
com.ptb.backendnode.tasks.DataMgrStatsCalculation.run(DataMgrStatsCalculation.java:78)<br>
java.util.TimerThread.mainLoop(Timer.java:512)<br>
java.util.TimerThread.run(Timer.java:462)<br>
</small><br>
<br>
<br>
Thanks!<br>
<br>
<br>
Michael Gentry escribi&oacute;:
<blockquote
 cite="mid:f65b8ae30801070743p18135e5cxe4272554971d64b1@mail.gmail.com"
 type="cite">
  <pre wrap="">Hi &Aacute;lvaro,

Creating a DataContext is a fairly cheap operation.  I would suggest
creating them as you need them and not try to optimize this operation
at this point.  If you run into bottlenecks in the future, then maybe
look at other options, but there is a good chance that creating extra
DataContexts will not be the source of a performance problem.

/dev/mrg


On Jan 7, 2008 10:30 AM, &Aacute;lvaro Mart&iacute;nez <a class="moz-txt-link-rfc2396E"
href="mailto:alvaro_martinez@ptbsl.com">&lt;alvaro_martinez@ptbsl.com&gt;</a>
wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Thanks, Andrus and Philip

The threads I'm talking about are created from many sources and for
different reasons. Not of all them are triggered in response to
"something". There are also watchers, periodic tasks... So I can't map
data contexts to some particular condition.

So then I have to create one data context per operation (that means a
set of actions). Is this expensive? We are developing a heavy loaded
cluster of servers, so it's important.

Thanks again!


Andrus Adamchik escribi&oacute;:

    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi &Aacute;lvaro,

It is hard to give a precise advice on multithreading without knowing
the nature of your application. So here is a few general notes:

* DataContext instance is your isolated area for making in-memory
changes to objects that will all be committed at once. So consider
using multiple contexts as appropriate. Cayenne docs recommend various
common patterns, such as DataContext per session (i.e. each user has a
dedicated context), DataContext per request, or DataContext per
application (in a read-only app). You can also devise your own
approach, if none of the above fit your needs. All you need to know
here is that multiple threads *reading* from a shared DataContext is
ok, but multiple threads *writing* to a shared DataContext is not ok.

* In a rare case if you really need multiple threads to work off of
the same context, consider using a dedicated nested DataContext for
each atomic object modifications.

Andrus


On Jan 7, 2008, at 2:44 PM, &Aacute;lvaro Mart&iacute;nez wrote:
      </pre>
      <blockquote type="cite">
        <pre wrap="">Hi, I've been working for a while with Cayenne but never realized
I
had a problem... until I got a weird exception.

The fact is that I had been using context.newObject() and
context.commitChanges() to create new rows in the database. But my
application works with many threads, so global commits can (and in
fact do) interrupt normal creation of objects. Thread A and Thread B
are creating objects and filling their fields, but then B commits all
and A throws a validation exception because mandatory fields are
missing.

How could I commit only one object?

Thanks,

&Aacute;lvaro from Spain (Push the button Inc.)



        </pre>
      </blockquote>
      <pre wrap="">

      </pre>
    </blockquote>
    <pre wrap="">
    </pre>
  </blockquote>
  <pre wrap=""><!---->

  </pre>
</blockquote>
<br>
</body>
</html>

Mime
View raw message