jakartaee / batch

The Jakarta Batch project produces the Batch Specification and API.
https://projects.eclipse.org/projects/ee4j.batch
Apache License 2.0
13 stars 17 forks source link

Support @PostConstruct and @PreDestroy callbacks in batch artifacts #44

Closed follis closed 2 years ago

follis commented 4 years ago

Originally opened as bug 5383 by cf126330

--------------Original Comment History---------------------------- Comment from = cf126330 on 2013-09-11 15:30:26 +0000

PostConstruct and PreDestroy callbacks enable applications to influence how batch container manages batch artifact lifecycles. Both classes are in already Java SE 6:

http://docs.oracle.com/javase/6/docs/api/javax/annotation/PostConstruct.html http://docs.oracle.com/javase/6/docs/api/javax/annotation/PreDestroy.html

For example,

@PostConstruct private void checkData() throws BatchRuntimeException { //make sure all injected properties are in place and valid. //do the necessary data conversion from string properties to other types //or consolidate several properties into 1 //or other initialization work }

@PreDestroy void cleanUp() { //clean up }

Currently there is no portable way to perform init and cleanup work in a batch artifact. So applications have to do it at the beginning of business processing methods, and have to take care to only perform it once.


Comment from = ScottKurz on 2016-03-24 14:39:42 +0000

If the batch artifact is loaded via CDI then PostConstruct and PreDestroy will be called.

So it seems the concern would be to standardize this across non-CDI artifact loading.

scottkurz commented 2 years ago

I don't think we're going to further standardize the non-CDI artifact loading but instead focus on better defining CDI integration. (Notifying @chengfang who originally opened this.)