I have a set of keys.
class X { private static String[] keys = {"k1", "k2", ... }; I have to extract values for the keys from a request. I think I can use map to extract values and create a list necessary objects in some request processing method like this:
public void processReq(Request req) { ... Stream.of(keys).map(k-> new Pack(k, req.getHeader(k))); But creating Stream per every request looks unnecessary task. If sharing Stream instance among multiple threads is safe, I think I can modify the code like this:
class X { private static Stream<String> keys = Stream.of("k1", "k2", ...); ... public void processReq(Request req) { ... keys..map(k-> new Pack(k, req.getHeader(k))); So, is sharing Stream instance among multiple threads like this safe?