Note that there are some explanatory texts on larger screens.

plurals
  1. POCookieManager for multiple threads
    text
    copied!<p>I am trying to make multiple connections via threads.</p> <p>But every connection seems to override the other's cookies, resulting in the connections using the wrong cookies.</p> <p>inside the threaded class's constructor:</p> <pre><code> manager = new CookieManager(); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); </code></pre> <p>Any way to manage the cookies per thread or per class?</p> <p>New failed try:</p> <p>Now every thread is using it's own index, yet they still seem to override each other cookie-wise. Any ideas?</p> <pre><code>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 cookies in store to persistent storage } public void add(URI uri, HttpCookie cookie) { store[index].add(uri, cookie); } public List&lt;HttpCookie&gt; get(URI uri) { return store[index].get(uri); } public List&lt;HttpCookie&gt; getCookies() { return store[index].getCookies(); } public List&lt;URI&gt; getURIs() { return store[index].getURIs(); } public boolean remove(URI uri, HttpCookie cookie) { return store[index].remove(uri, cookie); } public boolean removeAll() { return store[index].removeAll(); } } </code></pre> <p>Within the class:</p> <pre><code>threadedCookieStore cookiestore = new threadedCookieStore(index); manager = new CookieManager(cookiestore,CookiePolicy.ACCEPT_ALL); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload