代码之家  ›  专栏  ›  技术社区  ›  Daniel Trebbien

类urimatcher的match(uri)是否可重入?

  •  5
  • Daniel Trebbien  · 技术社区  · 15 年前

    我所看到的关于如何 ContentProvider 都用过了 UriMatcher#match(Uri) 中的方法 insert , query , update delete 方法来轻松处理内容提供者响应的所有URI模式(例如: http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html )直到今天,当我注意到 内容提供者 API文档 插入 , 查询 , 更新 删除 “可以从多个线程调用[全部]”。另外, UriMatcher 文档中没有提到线程安全或 match 是可重入的。

    我需要担心将呼叫同步到 比赛 关于共享的, static 实例 尿毒症患者 在我的实现中使用的 插入 , 查询 , 更新 删除 ?

    1 回复  |  直到 15 年前
        1
  •  6
  •   Daniel Trebbien    15 年前

    透视 the source of UriMatcher ,多线程 可以 打电话给 match 方法同时因为实现 比赛 仅访问每个线程变量 uri (参数),共享 String 和的元素 ArrayList<UriMatcher> (通过 ArrayList#get(int) ,这是线程安全的)。

    addURI 线程安全,因为它在结构上修改了 ArrayList . 是一样的 数组列表 那个 比赛 从中读取 阿杜里 当其他线程可能正在调用时无法调用 比赛 .