我在 Scala 2.10.2 上,想使用 Apache http 客户端 4.2.5 实现线程安全的 http 提供程序,这就是我所做的
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
import scala.concurrent.Future
object AsyncHttpProvider {
import org.apache.http.client._
import org.apache.http.client.methods._
import org.apache.http.impl.client._
val httpclient = new DefaultHttpClient
private def get(query: String) = {
val httpget = new HttpGet(query)
val brh = new BasicResponseHandler
httpclient.execute(httpget, brh)
}
def getResponseBodyAsJValue(query: String): Future[JValue] = Future(parse(get(query)))
def getResponseBodyAsJsonString(query: String): Future[String] = Future(get(query))
}
由于我正在使用Future
,我想确保代码是线程安全的,是吗?