I have certain objects on which certain tasks needs to be performed.On all objects all task needs to be performed. I want to employ multiple threads say N parallel threads
Say I have objects identifiers like A,B,C (Objects can be in 100 K range ; keys can be long or string) And Tasks can T1,T2,T3,TN - (Task are max 20 in number)
Conditions for task execution - Tasks can be executed in parallel even for the same object. But for the same object, for a given task, it should be executed in series. Example , say I have Objects on which are task performed are A,B,A and tasks are t1, t2
So T1(A), T2(A) or T1(A) , T2(B) are possible , but T1(A) and T1(A) shouldnt be allowed
How can I ensure that , that my conditions are met. I know I have to use some sort of hashing. I read about hashing , so my hash function can be of -
return ObjectIdentifier.getHashCode() + TaskIdentifier.getHashCode() or other can be - a^3 + b^2 (where a and b are hashes of object identifier and task identifier respectively) What would be best strategy, any suggestions
My task doesnt involve any IO, and as of now I am using one thread for each task. So my current design is ok, or should I try to optimize it based on num of processors. (have fixed num of threads )