Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello:
Can you provide example of this concurrentHashMap routine with get / set methods?
Thanks
Create a new Routine (under code in the repository list), call it UniversalMap, and paste this in there:
package routines; import java.util.concurrent.ConcurrentHashMap; public class UniversalMap { private static ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>(); public static <T> T put(String key, T value) { return (T) map.put(key, value); } public static <T> T get(String key) { return (T) map.get(key); } }
Then you can use it like this:
UniversalMap.put("hello","world"); String who = UniversalMap.get("hello"); System.out.println(who);
This is my version of the sharedMap infrastructure.
1. Add a context variable sharedMap to each job
2. Create a joblet:
3. Add this joblet to each job, and link it using an onComponentOK link at the start of the job
4. In the tRunJob components, pass the sharedMap context variable the value context.sharedMap
5. In PARENT, put the following code in a tJava:
((java.util.map) context.sharedMap).put( "listOfThings", "" );
6. In SUBJOB1, put the following code:
((java.util.map) context.sharedMap).put( "listOfThings", (String)(((java.util.map) context.sharedMap).get("listOfThings")) + my.thing );
...where my.thing is whatever you want to add
7. In SUBJOB2, use the following wherever you want to use the listOfThings:
(String)(((java.util.map) context.sharedMap).get( "listOfThings" ))