Right now I am using the PB.beginTransactoin, and PB.commit...
On Sat, 04 Dec 2004 18:53:43 +0100, Armin Waibel <[EMAIL PROTECTED]> wrote: > Hi Wesley, > > Wesley Lemke wrote: > > > I am using the integer as the lock field. On monday I can give it a > > shot with a timestamp. > > Integer is fine. There is a bug when using Timestamp values in OJB1.0.1, > so Integer is a better choice. > > > I just can't figure out why it works the first > > time I run it, but then the exception is not thrown after that. Could > > it have something to do with the data source getting a new connection > > the first time? > > > > hmm, if the used connections don't get committed side-effects could > happen. Do you use PB-tx demarcation (PB.beginT...) (or JTA-tx when in > managed environment)? > > I checked in a multithreaded optimistic locking test in CVS branch > OJB_1_0_RELEASE > > http://cvs.apache.org/viewcvs.cgi/db-ojb/src/test/org/apache/ojb/broker/OptimisticLockingMultithreadedTest.java?rev=1.1.2.1&only_with_tag=OJB_1_0_RELEASE&view=markup > > This test (multiple threads try to update the same object) seems to work > and case OLE when version conflict occur. > > regards, > Armin > > > > > > > > On Fri, 03 Dec 2004 23:01:48 +0100, Armin Waibel <[EMAIL PROTECTED]> wrote: > > > >>Hi Wesley, > >> > >>I did a multithreaded test too - all seems ok. > >>Do you use a Timestamp as lock field? > >>Do you re-read the used object when writing fails (to get fresh object > >>with valid lock version)? > >> > >>regards, > >>Armin > >> > >> > >> > >>Wesley Lemke wrote: > >> > >> > >>>I am now printing the ackOptLock value, but still am only getting the > >>>OptimisticLock exception the first time I run the code after I restart > >>>the servlet containter. Here is the log files of the first two runs. > >>> > >>>*************************** START ************************ > >>>SERVLET: Starting ClientAdderDelay > >>>SERVLET: Starting ClientAdder > >>>SERVLET: Joining to ClientAdder > >>>CLIENTADDERDELAY: Before Update: 00001:120 > >>>CLIENTADDERDELAY: Sleeping for 5000 millis > >>>CLIENTADDER: Before Update: 00001:120 > >>>CLIENTADDER: Changing name to 00000: 120 > >>>CLIENTADDER: After Update: 00000:121 > >>>SERVLET: Joingin to ClientAdderDelay > >>>CLIENTADDERDELAY: Changing name to 00000:120 > >>>CLIENTADDERDELAY: (121) > >>>org.apache.ojb.broker.OptimisticLockException: Object has been > >>>modified by someone else > >>>CLIENTADDERDELAY: After Update: 00000:121 > >>>*************************** END ************************ > >>> > >>>*************************** START ************************ > >>>SERVLET: Starting ClientAdderDelay > >>>SERVLET: Starting ClientAdder > >>>SERVLET: Joining to ClientAdder > >>>CLIENTADDERDELAY: Before Update: 00000:121 > >>>CLIENTADDERDELAY: Sleeping for 5000 millis > >>>CLIENTADDER: Before Update: 00000:121 > >>>CLIENTADDER: Changing name to 00001: 121 > >>>CLIENTADDER: After Update: 00001:122 > >>>SERVLET: Joingin to ClientAdderDelay > >>>CLIENTADDERDELAY: Changing name to 00001:122 > >>>CLIENTADDERDELAY: After Update: 00001:123 > >>>*************************** END ************************ > >>> > >>>Everything looks the same, to me except the first time the exception > >>>is thrown, and the database is only updated once, the second time the > >>>exception isn't thrown and the database is updated twice. > >>> > >>>Does anyone else have any suggestions on what I should try next? > >>> > >>>On Fri, 3 Dec 2004 10:25:04 +0100, Alessandro Colantoni > >>><[EMAIL PROTECTED]> wrote: > >>> > >>> > >>>>Hi Wesley. > >>>>I don't think the problem is the new connection. > >>>>It looks like thread B do his job (the second time, of course) after > >>>>thread A has done his one. > >>>>That's should be the reason you don't get the optimistic lock Exception > >>>>the second time (I don't see it). > >>>>You should print the value of the ackOptLock parameter to have more > >>>>informations. > >>>>I hope this help > >>>> > >>>>-----Mensaje original----- > >>>>De: Wesley Lemke [mailto:[EMAIL PROTECTED] > >>>>Enviado el: jueves, 02 de diciembre de 2004 22:51 > >>>>Para: OJB Users List > >>>>Asunto: Optimistic Locking Problem. > >>>> > >>>> > >>>> > >>>>We are adding optimistic locking to our application. To test it out I > >>>>have made a simple test case. The application spawns two threads. > >>>> > >>>>Thread A (ClientAdderDelay): Reads an object from the database. It > >>>>then checks the name of the ojbect. If the name was 00000 it changes > >>>>it to 00001 and if the name was 00001 it changes it to 00000. The > >>>>thread sleeps for 5 seconds and then stores the object. > >>>> > >>>>Thread B (ClientAdder): Does the same thing, but doesn't sleep 5 > >>>>seconds between the read/store. > >>>> > >>>>The main servlet starts thread A, then sleeps for 1 second and starts > >>>>thread B. > >>>> > >>>>The very first time I run the application everything works as it > >>>>should, Thread A and B both read 00000 from the database. Thread B > >>>>then updates the row to be 00001. Thread A gets and OptimisticLock > >>>>exception when it tries to store the object. > >>>> > >>>>However all subsequent times that I run the application Thread A will > >>>>get the correct value from the database but thread B will get the > >>>>opposite value. I am attaching the output, which will hopefully make > >>>>this more understandable. The one difference I see is that the > >>>>Datasource gets a new connection the first time the Servlet is run, > >>>>but not the second...I wouldn't think that this would matter? > >>>> > >>>>OUTPUT: > >>>> > >>>>[12/2/04 15:47:56:436 CST] 797e3663 SystemErr R > >>>>*************************** START ************************ > >>>>[12/2/04 15:47:56:466 CST] 797e3663 SystemErr R SERVLET: Starting > >>>>ClientAdderDelay > >>>>[12/2/04 15:47:56:466 CST] 797e3663 SystemErr R SERVLET: Sleeping > >>>>1000 millis > >>>>[12/2/04 15:47:56:896 CST] 6de77661 Config E > >>>>com.opensymphony.oscache.base.Config Error reading > >>>>/oscache.properties in CacheAdministrator.loadProps() > >>>>java.lang.NullPointerException > >>>>[12/2/04 15:47:56:906 CST] 6de77661 Config E > >>>>com.opensymphony.oscache.base.Config Ensure the /oscache.properties > >>>>file is readable and in your classpath. > >>>>[12/2/04 15:47:56:916 CST] 6de77661 GeneralCacheA I > >>>>com.opensymphony.oscache.general.GeneralCacheAdministrator > >>>>Constructed GeneralCacheAdministrator() > >>>>[12/2/04 15:47:56:916 CST] 6de77661 GeneralCacheA I > >>>>com.opensymphony.oscache.general.GeneralCacheAdministrator Creating > >>>>new cache > >>>>[12/2/04 15:47:58:469 CST] 6de77661 DSConfigurati W DSRA0174W: > >>>>Warning: GenericDataStoreHelper is being used. > >>>>[12/2/04 15:47:58:629 CST] 6de77661 ConnectionFac I J2CA0122I: > >>>>Resource reference jdbc/ao79 could not be located, so default values > >>>>of the following are used: [Resource-ref settings] > >>>> > >>>> res-auth: 1 (APPLICATION) > >>>> res-isolation-level: 0 (TRANSACTION_NONE) > >>>> res-sharing-scope: true (SHAREABLE) > >>>> res-resolution-control: 999 (undefined) > >>>>[Other attributes] > >>>> > >>>>isCMP1_x: false (not CMP1.x) > >>>>isJMS: false (not JMS) > >>>> > >>>>[12/2/04 15:47:58:669 CST] 6de77661 ConnectionFac I J2CA0107I: > >>>>Component-managed authentication alias not specified for connection > >>>>factory or datasource MySql Datasource on ao79. > >>>>[12/2/04 15:47:58:699 CST] 4b22f67d ConnectionFac I J2CA0122I: > >>>>Resource reference jdbc/ao79 could not be located, so default values > >>>>of the following are used: [Resource-ref settings] > >>>> > >>>> res-auth: 1 (APPLICATION) > >>>> res-isolation-level: 0 (TRANSACTION_NONE) > >>>> res-sharing-scope: true (SHAREABLE) > >>>> res-resolution-control: 999 (undefined) > >>>>[Other attributes] > >>>> > >>>>isCMP1_x: false (not CMP1.x) > >>>>isJMS: false (not JMS) > >>>> > >>>>[12/2/04 15:47:58:699 CST] 6de77661 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:47:58:709 CST] 4b22f67d ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:47:57:477 CST] 797e3663 SystemErr R SERVLET: Starting > >>>>ClientAdder > >>>>[12/2/04 15:47:57:477 CST] 797e3663 SystemErr R SERVLET: Joining > >>>>to ClientAdder > >>>>[12/2/04 15:47:59:170 CST] 4b22f67d WSRdbDataSour u Database version is > >>>> 3.23.41 > >>>>[12/2/04 15:47:59:170 CST] 4b22f67d WSRdbDataSour u JDBC Driver version > >>>>is > >>>> mysql-connector-java-3.0.15-ga ( > >>>>$Date: 2004/08/09 22:15:11 $, $Revision: 1.27.2.43 $ ) > >>>>[12/2/04 15:47:59:250 CST] 4b22f67d ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:47:59:250 CST] 6de77661 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:47:59:530 CST] 4b22f67d SystemErr R CLIENTADDER: > >>>>Before Update: 00000<br> > >>>>[12/2/04 15:47:59:560 CST] 4b22f67d SystemErr R CLIENTADDER: > >>>>Changing name to 00001 > >>>>[12/2/04 15:47:59:560 CST] 6de77661 SystemErr R CLIENTADDERDELAY: > >>>>Before Update: 00000<br> > >>>>[12/2/04 15:47:59:560 CST] 6de77661 SystemErr R CLIENTADDERDELAY: > >>>>Sleeping for 5000 millis > >>>>[12/2/04 15:47:59:570 CST] 4b22f67d ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:47:59:570 CST] 4b22f67d ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:47:59:590 CST] 4b22f67d SystemErr R CLIENTADDER: > >>>>After Update: 00001<br> > >>>>[12/2/04 15:47:59:590 CST] 797e3663 SystemErr R SERVLET: Joingin > >>>>to ClientAdderDelay > >>>>[12/2/04 15:48:04:557 CST] 6de77661 SystemErr R CLIENTADDERDELAY: > >>>>Changing name to 00001 > >>>>[12/2/04 15:48:04:617 CST] 6de77661 SystemErr R > >>>>CLIENTADDERDELAY:org.apache.ojb.broker.OptimisticLockException: Object > >>>>has been modified by someone else > >>>>[12/2/04 15:48:04:617 CST] 6de77661 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:48:04:627 CST] 6de77661 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:48:04:637 CST] 6de77661 SystemErr R CLIENTADDERDELAY: > >>>>After Update: 00001<br> > >>>>[12/2/04 15:48:04:637 CST] 797e3663 SystemErr R > >>>>*************************** END ************************ > >>>>[12/2/04 15:48:47:729 CST] 797e3663 SystemErr R > >>>>*************************** START ************************ > >>>>[12/2/04 15:48:47:729 CST] 797e3663 SystemErr R SERVLET: Starting > >>>>ClientAdderDelay > >>>>[12/2/04 15:48:47:729 CST] 797e3663 SystemErr R SERVLET: Sleeping > >>>>1000 millis > >>>>[12/2/04 15:48:47:779 CST] 1ec7f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:48:47:840 CST] 1ec7f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:48:47:850 CST] 1ec7f672 SystemErr R CLIENTADDERDELAY: > >>>>Before Update: 00001<br> > >>>>[12/2/04 15:48:47:850 CST] 1ec7f672 SystemErr R CLIENTADDERDELAY: > >>>>Sleeping for 5000 millis > >>>>[12/2/04 15:48:48:931 CST] 797e3663 SystemErr R SERVLET: Starting > >>>>ClientAdder > >>>>[12/2/04 15:48:48:931 CST] 797e3663 SystemErr R SERVLET: Joining > >>>>to ClientAdder > >>>>[12/2/04 15:48:48:931 CST] 1ec0f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:48:49:031 CST] 1ec0f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:48:49:041 CST] 1ec0f672 SystemErr R CLIENTADDER: > >>>>Before Update: 00000<br> > >>>>[12/2/04 15:48:49:041 CST] 1ec0f672 SystemErr R CLIENTADDER: > >>>>Changing name to 00001 > >>>>[12/2/04 15:48:49:051 CST] 1ec0f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:48:49:061 CST] 1ec0f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:48:49:081 CST] 1ec0f672 SystemErr R CLIENTADDER: > >>>>After Update: 00001<br> > >>>>[12/2/04 15:48:49:081 CST] 797e3663 SystemErr R SERVLET: Joingin > >>>>to ClientAdderDelay > >>>>[12/2/04 15:48:52:857 CST] 1ec7f672 SystemErr R CLIENTADDERDELAY: > >>>>Changing name to 00001 > >>>>[12/2/04 15:48:52:857 CST] 1ec7f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>allocateMCWrapper. > >>>>[12/2/04 15:48:52:867 CST] 1ec7f672 ConnectionMan W J2CA0075W: An > >>>>active transaction should be present while processing method > >>>>initializeForUOW. > >>>>[12/2/04 15:48:52:877 CST] 1ec7f672 SystemErr R CLIENTADDERDELAY: > >>>>After Update: 00001<br> > >>>>[12/2/04 15:48:52:877 CST] 797e3663 SystemErr R > >>>>*************************** END ************************ > >>>> > >>>>Let me know if any more information would be helpful... > >>>> > >>>>--------------------------------------------------------------------- > >>>>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>>For additional commands, e-mail: [EMAIL PROTECTED] > >>>> > >>>> > >>> > >>> > >>>--------------------------------------------------------------------- > >>>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >>> > >> > >>--------------------------------------------------------------------- > >> > >> > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
