Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another mock question

 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 public void onMessage(Message msg)
2 {
3 System.out.println("Message received.");
4 boolean flag = getBooleanProperty("myflag"); //assume flag is always true
5 if(flag)
6 {
7 throw new EJBException("Can't process this message."); //line 10
8 }
9 }


Which of the given options are correct regarding the following onMessage code for a message driven bean with container managed transactions and a transaction attribute of 'Required'?
Select 1 correct option.

a It is invalid because a message driven bean cannot throw an EJBException.

b It may potentially bring down the application server.

c It will work well if line 7 is replaced with: context.setRollbackOnly();

d It is a valid and harmless code that does nothing.
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My take on this -
D

Once it runs, Container is going to --
1. rollback the transaction.
2. log the error
3. discard the MDB instance.

Bean can thow EJBEXception, but contianer can not. Am I missing something?

Gemini
[ March 21, 2005: Message edited by: Gemini Moses ]
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option a, c and d are incorrect.

Is it because this code may produce poison messages, the author is worried that the application server would crash? Thats interesting!
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keerthi,

so what I said is wrong? ---

MDB Bean can throw EJBEXception, but contianer can not

Thanks,
Gemini

[ March 21, 2005: Message edited by: Gemini Moses ]
[ March 21, 2005: Message edited by: Gemini Moses ]
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gemini, I think MDB beans as well as container can throw EJBException.
Keerthi mentioned about poison messages. In CMT beans the message acknowledge is tied to the status. If bean can't commit, that message will keep coming back again n again. But still I don't understand how can it harm application server?
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The ApplicationServer comes down because onMessage is being invoked infinetly in this case.

Thanks

Ravi
 
amol deshpande
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
My take is that ..
you can throw eje exception so 1 is wrong.
setRollbackOnly is ok.
Amol.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic