Avatar billede fredand Forsker
11. juni 2006 - 09:38 Der er 14 kommentarer og
1 løsning

Delicate concurrency access problem

Hello!

I have a problem with tow apps that is accessing the same object in a database.

Short description is that app 1 creates the object a triggers fires and app 2 should read the object from the database. How ever the trigger fires to quick and the object may not have been stored to the database when app 2 is accessing it. I guess you see the problem.


Long description
app 1 is running in a weblogic and posts a JMS-message on a OpenJMS queue (we do not have license for JMS in our weblogic). This happens when a object is created. Unfortunately this is not an ordinary database so we can not use SQL and ordinary triggers. I guess the implementation works alot like Hibernate. Then I guess the trigger fires when the object is created in the RAM and not in the underlaying database that is in this case an Oracle database (but we can not get hand on the oracle at all).

When the triger fires app 1 posts the JMS-message that is in indication two app 2that it should read this newly created object and do some stuff. This app 2 is running in a TomCat.

When app 2 is accessing the database the object is not created and stored yet.

If we could use Weblogic there is a "Time To Deliver Override" to set on the topic that app posts to but I guess there is nothing like this in OpenJMS.

Perhaps the only solution for this is that app 2 when it gets a message it instances a threaded app that waits for a couple of secs before it proceed?

What do you think?

All comments are welcome!!

Best regards

Fredrik
Avatar billede arne_v Ekspert
11. juni 2006 - 15:44 #1
how is app 1 saving to the Oracle database ?

if it is through entity EJB then you should be able to fix it by switching
to commit option C

(though that may hurt performance)

commit option B is not compatible with other apps using the same data
Avatar billede arne_v Ekspert
11. juni 2006 - 16:32 #2
hm - forget the C versus B thing - if that was the problem, then app 1
would not see app 2's changes - not the other way around

but you should definatetly be using C anyway though

it is still very relevant to know how app 1 is saving the data and how that
is related to sending the JMS message
Avatar billede fredand Forsker
11. juni 2006 - 20:45 #3
Hello!

Unfortunately I'm not able to tell how exactly app 1 is saving the data. I only guess that nit looks like it takes some time like 1 sec or 2. So my aim is to delay the app 2 when it gets notified about it. So if ypou got ant ideas how to delay app 1 in the best way. Please let me know.

I guess you think a delay does not sound very safe, neither do I. But it looks like this will solve the problem.

Best regards
Fredrik
Avatar billede arne_v Ekspert
11. juni 2006 - 22:37 #4
a delay wil always only be a 99.9% solution not a 100% solution

it is generally not good for performance to do delays
Avatar billede arne_v Ekspert
11. juni 2006 - 22:38 #5
maybe app 1 is sending the JMS message before it commits the data ??
Avatar billede arne_v Ekspert
11. juni 2006 - 22:40 #6
but if you can not change app 1 and not even look at app 1, then you can
probably not do much else than wait

can app 2 see in data if is not updated in the db so that it can try and wait again
if necesarry ?
Avatar billede fredand Forsker
12. juni 2006 - 08:56 #7
Hello!

Yes I think it is possible for app 2 to do this check if the data is updated.

Do you think a good solution for a delay then would be a started Thread that waits until the data is changed?

Or do you see anything else as a nice delay solution? Correct me if I am wrong when I say that Thread.sleep(5000); stops the entire app for 5 secs.

Best regards
Fredrik
Avatar billede arne_v Ekspert
12. juni 2006 - 12:56 #8
Thread.sleep only stops current thread for 5 seconds not the entire app
Avatar billede arne_v Ekspert
12. juni 2006 - 12:58 #9
I thougth you already had a listener thread to read from the queue
Avatar billede arne_v Ekspert
12. juni 2006 - 12:59 #10
Maybe (just maybe) it would be an option to put a transaction manager in your
Tomcat, integrate that with your message queue and simply rollback if you are
not ready
Avatar billede fredand Forsker
12. juni 2006 - 16:48 #11
Hello!

Perhaps I'm a bit offside regarding to your comment:
I thougth you already had a listener thread to read from the queue

Correct me if I'm wrong if I say that if I instantiate my listener from a servlet during init of that servlet. Then I have a own thread for this listener together with that servlet? If I then run Thread.sleep(5000) from inside the listener I will stop this Thread for 5 sec? Since this is the only thing I have in this app, I may have been sloppy saying that the whole app will stop. Or have I missunderstand how a servlet is running in a thread of there own?

How ever what you said about a transaction manager I guess this must be the correct thing to do. Unfortunately I do not know so much about this but there rings a bell about JTA. If you got any hints I where to start I would appreciate it a lot.

Best regards
Fredrik
Avatar billede arne_v Ekspert
12. juni 2006 - 18:17 #12
usually there are only one instance of a servlet class

each request (or startup) runs in its own thread

----

I do not know much about Tomcat and JTA but Google finds http://jotm.objectweb.org/current/jotm/doc/howto-tomcat-jotm.html
Avatar billede arne_v Ekspert
12. juni 2006 - 18:22 #13
Avatar billede fredand Forsker
14. juni 2006 - 10:21 #14
Hello!

Thanks alot!
Consulting you has always turned out to a succsess!

BTW give a svar so I can reward you mate!
Best regards
Fredrik
Avatar billede arne_v Ekspert
14. juni 2006 - 13:10 #15
svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester