Hi Jinhui,
I don't know exactly what is your functional need, but I understand something like a service, which because of an external input has to update in a consistent manner several databases.
If yes, I'll do two separate process : one which will scan the external input and prepare data; then will call the second whose job is only to update the databases.
By doing so, when the second process has finished his job, DI-API context is going to be correctly cleaned.
Regards,
Eric