I am writing a scheduler which grabs XML data and inserts into MySQL DB – simple isn’t. But the problem or the logic that I am trying to find is here. NOTE: I want to execute this in windows environment in future it might be configured for other platforms.
- Scheduler should run on every 5 mins.
- This script should fetch condition/configuration on what to parse and collect the data-fields from XML and these conditions are available from MySQL table.
- This table also defines a delay in which this script should check for the difference in the XML fields & delay.
- This script does both, one is running for every 5 mins to collect XML and check the difference in the table (MySQL) for every said delay.
- This script then reads the XML data-fields and parses it, then collects only those data-fields that is defined from the above MySQL table.
- The collected data will be inserted into MySQL DB only when there is change in the state and this state is defined from MySQL table.
Feedback/Suggestions:
- Due to the delay, I am not sure how should I store the configuration in the script which will be shared between each schedules.
- Is there anyway to use
staticvariable in the code to store this data? Which will be shared b/w different jobs? or different schedules? - Basically, how should I implement this? A better approach in terms of performance.
Thanks for your time.
UPDATE:
One of the suggestion is to use Java Code as a windows service (?) we could have some common data shared between different jobs? – does it make sense?
Reference:
Java Service Wrapper
Concurensy is the answer, try creating Thread pool or Executor servises, and stop certain threads for 5min , you coud even use Synchronization if few threads will be working with the same resource.
Remember not always the more threads use the faster you will finish your job f.e. 3 threads- 2 min
5threads-6 min
*Read tutorial about threads
*create fe simple threads with wait for 5 min
*read some tutorials about thread pool/synchnizations and sharing resourses (script part)
*test to find the most optimal way