How to use different cookies for each connection using HttpURLConnection and the CookieManager in Java
问题 I needed to connect to a website from multiple threads simultaneously using HttpURLConnection, but use different cookies for each connection. Since Java only supports setting a global CookieManager, I've implemented the following hack. Instead of calling CookieHandler.setDefault(new CookieManager()) , I've implemented a custom CookieHandler which uses a different CookieStore instance for every thread, which is cleared after each request. I've created class called SessionCookieManager based on