java - How to finish a container-managed transaction before running a long task? -
i have task consists of 3 steps prepare
, execute
, update
. prepare
, update
need work within transaction, whereas execute
takes long (i.e. several minutes hours). task part of ejb, i.e.:
@stateless public class task { public void dotask() { prepare(); execute(); update(); } }
my question is, there (elegant) way commit , finish transaction after prepare
, start new 1 before update
? i'd rather use container-managed transactions , possibly not switch use usertransaction
.
it possible split tasks single ejbs if gains advantage, note suspending transaction execute
(i.e. using @transactional(txtype.not_supported)
not enough since still triggers timeout.
i tried split taskexecute
class has @asynchronous @transactional(not_supported) public void execute()
, sending event when done. doesn't seem work either.
is there way this?
after further testing let me conclude: alexanders reply absolutely correct. understanding had altered. foremost, wasn't aware @transactional
not work on ejbs, on cdi beans. ejbs annotation called @transactionattribute
, can set same values. combination of @asynchronous
, @transactionattribute(not_supported)
work (if not waiting result).
it depends on version of java ee want use. here 3 possible solutions.
- use jms, send appropriate message ,
execute
in mdb (any version, full profile required) - use java ee 6.0's timer service , schedule task perform
execute
asynchronously (@timeout
) - use java ee 7.0's batch processing api schedule proper long running batch job.
the latter looking for, available in java ee 7.0 , up. otherwise, jms solutions cleanest, if jms not option, timer service should work.
Comments
Post a Comment