• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Interview Question in a reputed investment bank on transaction.

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I went to an interview with a reputed investment bank I was asked a question on transaction as below

' Your transaction involves two parts : a JMS message generation and a DB operation. you have sent the message to the JMS provider and Database insert fails then how you are going to manage transaction?'

Please help find an answer to this question..

Regards

Guy
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Was the word "transaction" actually used in the question? If so, then I will speculated that this was a leading question, and the interviewer wanted to discuss "transactions".

Transactions are optionally supported by both JMS and Databases (JDBC), and the interviewer probably wanted you to discuss such support. Additionally, since two different systems that support transactions, was mentioned, the interview probably wanted you to discuss the concept of "two phase commit".

Henry
 
Guy Emerson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry for your insights.

Was the word "transaction" actually used in the question?



Yes it was asked the way I narrated in my post.

Additionally, since two different systems that support transactions, was mentioned, the interview probably wanted you to discuss the concept of "two phase commit".



Would you help explain how one would apply a Two phase commit in a method that involves a JMS message sending and a DB insert. if the DB insert fails the JMS message should also be rollbacked. This would be great insight for me as well as a lot of others to better their comprehension on this topic.

Regards

Guy
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ideally you would be working in an environment which already supports distributed transactions, so you wouldn't exactly be using two-phase commit in the sense of writing your own transaction-managing code. You'd just use the built-in facilities of the transaction manager that's already there.

Now having said that, I don't know the details of that because I haven't ever had to deal with it. But basically you start a transaction, you ensure that your JMS facility is registered to participate in that transaction, you send the JMS message. Then you ensure that your JDBC driver is also registered with the transaction manager, you try to do the insert, it fails, and you roll back the transaction. That causes the JMS message to be not sent, or unsent, or however the transaction manager handles that.

I've heard of "two-phase commit", but I don't know how it works. That's the same as a large number of other concepts in the computing field -- I don't know how it works really and I don't have to know. So it's just a buzzword. But mentioning buzzwords does get you kudos even if you don't understand the details.
 
author & internet detective
Posts: 42162
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wikipedia has a pretty good description. I knew about the polling/voting, but not everything on that page. Because as Paul said, the driver handles the low level details
 
Ranch Hand
Posts: 441
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Now having said that, I don't know the details of that because I haven't ever had to deal with it. But basically you start a transaction, you ensure that your JMS facility is registered to participate in that transaction, you send the JMS message. Then you ensure that your JDBC driver is also registered with the transaction manager, you try to do the insert, it fails, and you roll back the transaction. That causes the JMS message to be not sent, or unsent, or however the transaction manager handles that.



Hi Paul,

I am just wondering that JMS and Database are two different systems, so, how they will be able to use the same transaction system to be in sync.. Any inputs will be highly appreciated. Thanks in advance.
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:Hi Paul,

I am just wondering that JMS and Database are two different systems, so, how they will be able to use the same transaction system to be in sync.. Any inputs will be highly appreciated. Thanks in advance.



I can't imagine why you would ask me that after what I wrote in my last post.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic