Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreparedStatement executeBatch Java heap space #114

Closed
super11892235 opened this issue Jun 28, 2016 · 1 comment
Closed

PreparedStatement executeBatch Java heap space #114

super11892235 opened this issue Jun 28, 2016 · 1 comment

Comments

@super11892235
Copy link

private void initDBConnection(){        
    try {
        conn.setAutoCommit(false);          
        StringBuffer sb = new StringBuffer();
        sb.append(" insert into t_mv_owner_x(videoid,kugouid,userid,deleteTime,deleteStatus,selfdirect,");
        sb.append(" relation)");                
        sb.append(" values(?,?,?,?,?,?,?)");
        pres = conn.prepareStatement(sb.toString());            
    } catch (SQLException e1) {
        log.error("init 3006 DB exception:",e1);
    }
}


private void batchInsert(List<MvOwner> Owners) throws SQLException{
    for (MvOwner vo : Owners) {
        pres.setLong(1, vo.getVideoid());
        pres.setLong(2, vo.getKugouid());
        pres.setLong(3, vo.getUserid());
        pres.setInt(4, vo.getDeleteTime());
        pres.setInt(5, vo.getDeleteStatus());
        pres.setInt(6, vo.getSelfdirect());
        pres.setInt(7, vo.getSelfdirect());
        pres.addBatch();
    }
    pres.executeBatch();
    conn.commit();
    pres.clearBatch();
    Owners.clear();
}



    TableRule ownerRule = TableRule.builder("t_mv_owner_x").actualTables(Arrays.asList("t_mv_owner_0", "t_mv_owner_1")).dataSourceRule(dataSourceRule).build();
    ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Arrays.asList(ownerRule))
            .bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(ownerRule))))
            .tableShardingStrategy(new TableShardingStrategy("videoid", new SingleKeyModuloTableShardingAlgorithm())).build();
    return new ShardingDataSource(shardingRule);
@hanahmily
Copy link
Contributor

@super11892235 本次修改避免了反复解析SQL。但是如果一次批量执行过多,还是会有oom的风险。原因是sjdbc内部的一些状态也需要进行保留

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants