-
Enhancement
-
Resolution: Done
-
Major
-
1.0.1.Beta
-
None
Some resources are expensive to create, like MongoClient, JsonFactory, and so should be shared between the reader class and the corresponding writer class if they are can be safely shared. Sometimes, they cannot be shared, for example, the writer writes to a different mongodb instance running in a different host.
If a particular resource in various steps within a job are configured the same way, it should be shared.
How to pass a resource (MongoClient, JsonFactory, etc) from reader to writer?
- stepContext transientUserData (does not support key-value pair, only single-value data) https://java.net/bugzilla/show_bug.cgi?id=4776
- store it in ThreadLocal, but how can we share the same MongoClient among different threads/partitions? We dont' want each partition to create a new MongoClient.
- maintain a ConcurrentMap, with jobName as the key, to store MongoClient. It seems com.mongodb.Mongo.Holder already implements such ConcurrentMap for caching MongoClient.
- store it in JNDI as a custom resource, if running in WildFly, and jberet-support should have an option to allow JsonFactory to be looked up via jndi instead of instantiated by application itself.