【发布时间】:2015-03-09 13:31:05
【问题描述】:
我看到的大多数 RxJava 示例都与网络调用有关。我是这个框架的新手,所以我想知道将它用于并行文件解析之类的东西是否也有意义。我有一个文件目录,我需要将其数据解析为 SQL 表。 我可以用 RxJava 做到这一点吗?我希望它尽可能多线程以提高效率。
数据描述
我的数据具有以一堆部分开头的层次结构。每个 Section 包含一个或多个 Subsection。每个 Subsection 包含一个或多个 HTML 文件。
SQL 表
sqlite> SELECT * FROM sections;
_id ordinal title
---------- ---------- ----------
1 1 Management
2 2 Emergency Preparedness
-- 有一个引用sections表的外键
sqlite> SELECT * FROM subsections;
_id ordinal chapter_id title
---------- ---------- ---------- ----------
1 A 1 General
2 B 1 Resources
-- 具有引用部分和子部分表的外键
sqlite> SELECT * FROM html;
_id chapter_id subsection_id number html_filename
---------- ---------- ---------- ---------- --------------
1 1 1 1 /1a-1.html
2 1 1 2 /1a-2.html
3 1 1 3 /1a-3.html
4 1 1 4 /1a-4.html
5 1 2 1 /1b-1.html
6 2 2 1 /2a-1.html
7 2 2 2 /2a-2.html
8 2 2 1 /2b-1.html
_id 字段是一个自动递增的主键(这不会每次都匹配序数)。 subsections 表依赖于接收其相关部分的主键。这意味着一旦插入Section 1,就可以插入Section 1a、1b、1c等(但不能2a)
目录结构
//Section 1
/1.title
//Subsection A
/1a.title
//html files for 1a
/1a-1.html
/1a-2.html
//Subsection B
/1b.title
//html files for 1b
/1b-1.html
/1b-2.html
//Section 2
/2.title
/2a.title
//..etc
每个 SQL 插入都可以使用 java builder 类构建,对于 /1b-2.html 来说,它看起来像这样
db.insert(HTML_TABLE, null, new HTML.Builder()
.chapterId(section1)
.letterId(subsectionB)
.number(2)
.build());
我最终将有大约 50-60 个部分,但整个部分的每个 SQL 插入、其子部分及其 HTML 文件都可以并行插入。对于这样的事情,使用 RxJava 有意义吗?
【问题讨论】:
标签: java multithreading system.reactive rx-java rx-android