java - Is ecwid-mailchimp library thread safe? -


i integrating spring based web application mailchimp using library

the comment in sample code shown on it's wiki home page says:

// reuse same mailchimpclient object whenever possible

as per advice, i'm using mailchimpclient object instance variable in class annotated @service, however, causing exceptions in server log make me think class may not thread-safe. can confirm?

exception stack trace

java.lang.illegalstateexception: invalid use of basicclientconnmanager: connection still allocated. make sure release connection before allocating one. @ org.apache.http.impl.conn.basicclientconnectionmanager.getconnection(basicclientconnectionmanager.java:162) ~[httpclient-4.2.3.jar:4.2.3] @ org.apache.http.impl.conn.basicclientconnectionmanager$1.getconnection(basicclientconnectionmanager.java:139) ~[httpclient-4.2.3.jar:4.2.3] @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:456) ~[httpclient-4.2.3.jar:4.2.3] @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:906) ~[httpclient-4.2.3.jar:4.2.3] @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:805) ~[httpclient-4.2.3.jar:4.2.3] @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:784) ~[httpclient-4.2.3.jar:4.2.3] @ com.ecwid.mailchimp.connection.httpclientconnectionmanager.post(httpclientconnectionmanager.java:63) ~[ecwid-mailchimp-2.0.1.0.jar:na] @ com.ecwid.mailchimp.mailchimpclient.execute(mailchimpclient.java:74) ~[ecwid-mailchimp-2.0.1.0.jar:na] @ com.ecwid.mailchimp.mailchimpclient.execute(mailchimpclient.java:83) ~[ecwid-mailchimp-2.0.1.0.jar:na] @ com.ecwid.mailchimp.mailchimpclient.execute(mailchimpclient.java:95) ~[ecwid-mailchimp-2.0.1.0.jar:na] 

the short answer no: instances of mailchimpclient not thread safe , therefore should not shared among threads.

the long answer: depends on implementation of mailchimpconnectionmanager passed constructor. if implementation thread safe, mailchimpclient instance thread safe well. however, existing implementations (httpclientconnectionmanager, javaneturlconnectionmanager) not thread safe.

thus, if need mailchimpclient shared among threads, write own (thread safe) implementation of mailchimpconnectionmanager , pass constructor.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -