我试图通过线程建立多个连接.
但是每个连接似乎都会覆盖其他连接,导致连接使用错误的cookie.
在线程类的构造函数内:
manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
Run Code Online (Sandbox Code Playgroud)
有没有办法管理每个线程或每个类的cookie?
新的失败尝试:
现在每个线程都使用它自己的索引,但它们似乎仍然以cookie方式覆盖彼此.有任何想法吗?
public class threadedCookieStore implements CookieStore, Runnable {
CookieStore[] store = new CookieStore[1000];
int index;
public threadedCookieStore(int new_index) {
index = new_index;
// get the default in memory cookie store
store[index] = new CookieManager().getCookieStore();
// todo: read in cookies from persistant storage
// and add them store
// add a shutdown hook to write out the in memory cookies
Runtime.getRuntime().addShutdownHook(new Thread(this));
}
public void run() {
// todo: write …Run Code Online (Sandbox Code Playgroud)