BufferedWriter多线程上传示例_批量数据通道SDK示例_数据上传下载_开发_MaxCompute-

BufferedWriter多线程上传示例_批量数据通道SDK示例_数据上传下载_开发_MaxCompute

阿里云服务器优惠

BufferedWriter多线程上传示例

本文通过代码示例向您介绍如何使用BufferedWriter接口实现多线程上传。

class UploadThread extends Thread {
  private UploadSession session;
  private static int RECORD_COUNT = 1200;
  public UploadThread(UploadSession session) {
    this.session = session;
  }
  @Override
  public void run() {
    RecordWriter writer = up.openBufferedWriter();
    Record r = up.newRecord();
    for (int i = 0; i < RECORD_COUNT; i++) {
      r.setBigint(0, i);
      writer.write(r);
    }
    writer.close();
  }
};
public class Example {
  public static void main(String args[]) {
   // 初始化MaxCompute和tunnel的代码
   TableTunnel.UploadSession uploadSession = tunnel.createUploadSession(projectName, tableName);
   UploadThread t1 = new UploadThread(up);
   UploadThread t2 = new UploadThread(up);
   t1.start();
   t2.start();
   t1.join();
   t2.join();
   uploadSession.commit();
}

赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  • potplayer
  • directx