java - Inserting enum values into HashMap -
i doing program in need insert enum values hashmap. can that? tried out in many ways, failed.
can please me? through program need implement hashmap containing 4 threadpools (whose names act key) corresponding have threapoolexcecutor object.
below given code :
public class mythreadpoolexcecutorpgm { enum threadpoolname { dr, pq, event, miscelleneous; } private static string threadname; private static hashmap<string, threadpoolexecutor> threadpoolexecutorhash; public mythreadpoolexcecutorpgm(string p_threadname) { threadname = p_threadname; } public static void fillthreadpoolexecutorhash() { int poolsize = 3; int maxpoolsize = 3; long keepalivetime = 10; threadpoolexecutor tp = null; threadpoolexecutorhash = new hashmap<string, threadpoolexecutor>(); threadpoolname poolname ; tp = new threadpoolexecutor(poolsize, maxpoolsize, keepalivetime, timeunit.seconds, new arrayblockingqueue<runnable>(5)); threadpoolexecutorhash.put(poolname,tp); //here failing implement currect put() }
you may want consider using enummap
instead of hashmap
here. enummap
faster , more space-efficient hashmap
when using enumerated values, seems precisely you're doing here.
Comments
Post a Comment