全部产品
MaxCompute

BufferedWriter多线程上传示例

更新时间:2017-06-07 13:26:11   分享:   

代码片段:

  1. class UploadThread extends Thread {
  2. private UploadSession session;
  3. private static int RECORD_COUNT = 1200;
  4. public UploadThread(UploadSession session) {
  5. this.session = session;
  6. }
  7. @Override
  8. public void run() {
  9. RecordWriter writer = up.openBufferedWriter();
  10. Record r = up.newRecord();
  11. for (int i = 0; i < RECORD_COUNT; i++) {
  12. r.setBigint(0, i);
  13. writer.write(r);
  14. }
  15. writer.close();
  16. }
  17. };
  18. public class Example {
  19. public static void main(String args[]) {
  20. // 初始化 MaxCompute 和 tunnel 的代码
  21. TableTunnel.UploadSession uploadSession = tunnel.createUploadSession(projectName, tableName);
  22. UploadThread t1 = new UploadThread(up);
  23. UploadThread t2 = new UploadThread(up);
  24. t1.start();
  25. t2.start();
  26. t1.join();
  27. t2.join();
  28. uploadSession.commit();
  29. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?