谁能解释为什么我的插入在 Ormlite 中需要这么长时间?在桌面上的一个 sqlite 事务中执行 1,700 次插入只需不到一秒钟。但是,当使用 Ormlite for Android 时,大约需要 70 秒,我可以在调试消息中看到每个插入。
当我尝试将插入包装到一个事务中时,它的速度完全相同。我知道 Android 和 Ormlite 都有开销,但是,我不认为它会那么好。我的代码如下:
    this.db = new DatabaseHelper(getApplicationContext());
    dao = db.getAddressDao();
final BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.poi)));
    try {
        dao.callBatchTasks(new Callable<Void>() {
            public Void call() throws Exception {
                String line;
                while ((line = reader.readLine()) != null) {
                    String[] columns = line.split(",");
                    Address address = new Address();
                    // setup Address
                    dao.create(address);
                } 
            return null;
         }
        });
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }