MaxCompute用户指南:批量数据通道SDK示例: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();
- }
收起
行者武松
2017-10-23 15:36:55
1816
0
0
条回答
写回答
取消
提交回答