4848import java .util .concurrent .ScheduledFuture ;
4949import java .util .concurrent .ScheduledThreadPoolExecutor ;
5050import java .util .concurrent .TimeUnit ;
51- import java .util .concurrent .atomic .AtomicInteger ;
5251import java .util .regex .Matcher ;
5352import java .util .regex .Pattern ;
5453import java .util .stream .Collectors ;
@@ -84,7 +83,7 @@ public class ImpalaOutputFormat extends AbstractDtRichOutputFormat<Tuple2<Boolea
8483 protected transient PreparedStatement statement ;
8584
8685 private transient volatile boolean closed = false ;
87- private final AtomicInteger batchCount = new AtomicInteger ( 0 ) ;
86+ private int batchCount = 0 ;
8887
8988 protected String keytabPath ;
9089 protected String krb5confPath ;
@@ -216,7 +215,8 @@ private void openJdbc() {
216215 private void flush () throws SQLException {
217216 if (Objects .nonNull (statement )) {
218217 statement .executeBatch ();
219- batchCount .set (0 );
218+ batchCount = 0 ;
219+ statement .clearBatch ();
220220 }
221221 }
222222
@@ -271,9 +271,10 @@ public void writeRecord(Tuple2<Boolean, Row> record) throws IOException {
271271 setRowToStatement (statement , fieldTypeList , rowValue , null );
272272 }
273273
274+ batchCount ++;
274275 statement .addBatch ();
275276
276- if (batchCount . incrementAndGet () >= batchSize ) {
277+ if (batchCount > batchSize ) {
277278 flush ();
278279 }
279280 } catch (Exception e ) {
@@ -296,7 +297,7 @@ public void close() throws IOException {
296297 this .scheduler .shutdown ();
297298 }
298299 // 将还未执行的SQL flush
299- if (batchCount . get () > 0 ) {
300+ if (batchCount > 0 ) {
300301 try {
301302 flush ();
302303 } catch (Exception e ) {
0 commit comments