I have a situation whereby there are a number of classes to handle different scenario( for example download file from some host, creating a new file to specific location, rename of a file etc).
This is the sistuation
1. a number of rules are running on a near realtime basis and corresponding to each rule there is a class
2. Each class has some execute method (similar to what we do for Command pattern) and the execute method performs the specific task (for example rename)
3. The execute method has no global variables. All the details are passed in as argument and the method extracts value from the arguments.
4. There are a number of threads (say 10) which keeps running all the rules. While running the rule, based on some runtime parameter, thread determines which rule to run and creates an object of the rule and calls its execute.
I am planning to do some performance improvement and am planning to keep a cache of the rule object being created (kind of Singleton pattern whereby a rule object is created only once and can be used by multiple threads). This way there will be no need to create a specific rule object everytime before it gets executed (there are around 20-25 rules and each rule gets executed more than 10000 times on a day. Doing the caching will avoid object creation 10000 times)
Though I don't see any issue doing this , I am trying to understand if there is something more that I can do to do performance improvement. If someone can provide pointers , it will be helpful.