No, i don't think so ...
I need something like the following
PseudoCode:
| @Stateful
| @Startup
| @Name("batch")
| @Scope (ScopeType.APPLICATION)
| @TransactionManagement (TransactionManagementType.BEAN)
| public class BatchBean implements Batch {
|
| private AtomicBoolean atomicBoolean = new AtomicBoolean();
|
| // Stateless bean
| @In IncomingMessages incomingMessages;
| // Stateless bean
| @In Task task;
| @Resource SessionContext sessionContext;
|
| @Asynchronous
| @Create
| public void parent () {
|
| atomicBoolean.set(Boolean.TRUE);
| task.init (incomingMessages);
|
| while (atomicBoolean.get()) {
|
| try {
| Thread.sleep(100);
| } catch (InterruptedException ie ) {
| // nothing
| }
|
|
| while (atomicBoolean.get()) {
| UserTransaction tx =
sessionContext.getUserTransaction();
| try {
| tx.begin();
| Object o = incomingMessages.next();
| if (o != null) {
| // synchonous call
| task.doTask(o);
| tx.commit();
| } else {
| tx.commit();
| break;
| }
| } catch (Exception e) {
| tx.rollback();
| }
| }
| }
| }
|
| @Shutdown
| public void destroy () {
| task.finishLastMessageAndClose();
| atomicBoolean.set(Boolean.FALSE);
| }
| }
|
@Shutdown is called before @Destroy and @Remove on undeployment and
server-shutdown
This approach is not possible because an applicationbean cannot be invoked by
two different threads at the same time ... (the parent- and the destroy-method)
Second there is no @Shutdown which waites for the asynchronous 'parent'-method
to finish after invokation of the @Shutdown - method ...
As asked in another thread i had also problems to get BEAN-managed transactions
work with seam-components .. For the most components i need CONTAINER-managed
Transactions, therefore i've installed
<transaction:ejb-transaction/>
in components.xml
The MBean - approach above (Fri Sep 21, 2007 10:41 AM) creates a simple Thread,
initialize it with the beans and have it run, but this has the sideeffect, that
the method-invokations incomingMessages.next() and task.doTask() are running
both in there own transactions ... that could cause the loss of messages ... ).
As described before there is also a problem to synchronize the MBean with the
Component-creation (Task, IncomingMessages) because the MBean is earlier up
than seam. And second the MBean lives on shutdown and on undeploy longer than
seam ..
Maybe i'm mixing some concepts which should better stand alone ..
I've not much experience with EJB3, Jboss, etc.
;)
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088956#4088956
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088956
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user