This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Container behaviour for MDB with timers  RSS feed

 
Asokan Srinivasan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a MDB that is schedulable. ie.. MDB should not process the messages in the message destination if a flag in database column is OFF and vice-versa. The MDB code resembles like

@MessageDriven
public class JmsTimerBean implements MessageListener {
@Resource TimerService timerService

public void onMessage(Message message){
MapMessage mapMessage = (MapMessage)message;
if(canIProcess()) {
doProcess();
} else{
Timer timer = timerService.createTimer(expirationDate, null );
timer.start(....);
}
}

@Timeout
public void timeout( ){
if(canIProcess()) {
doProcess();
} else{
Timer timer = timerService.createTimer(expirationDate, null );
timer.start(....);
}
}

private boolean canIProcess( ){
return db.get(flag);
}


I assume the following scenareos
1. When a message arrives at the queue and the db flag is OFF, a timer is started for that particular mdb instance. When the timeout method is called, it checks for the flag and the process is repeated as long as the flag is ON, the message gets processed
2. If suppose 10 messages arrive at the destination and 10 instances of MDB are in the container pool they will undergo the process in scenareo 1
3. If suppose 100 messages arrive at the destination, will the container create as many number of MDB instances and undergo the same process in scenareo 1??? If this so, whether it will cause low performance issues or high resource utilisation??

can this timer be made common to all mdb instances?
Is this mechanism of scheduling mdb a good design?
Is there any alternative better method with MDB or other java enterprise technology to achieve a similar goal?


 
Asokan Srinivasan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some tests on the MDB and found the following.

MDB can be made single threaded so that they can have a FIFO by setting listener-threads attribute of message-driven-deployment, a tag in orion-ejb-jar.xml. This configuration file is specific to oc4j container. For making MDB to follow a FIFO pattern of processing the messages, this option looks quite promising. I wonder why the EJB spec does not standardise this feature.

If the MDB is made single threaded by following the above, then the container will not generate multiple threads, no matter how many messages are waiting in queue

But still to make the MDB to pause/resting stage(temporary stop), I have to check on a database table column for every request and trigger a timer based on that.

can there be any better solution for scheduling MDB to rest at night and make it work only when I am working??

thanks experts for your suggestions if any

Asokan S
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!