@@ -0,0 +1,2000 @@
+package cassandra.tests;%0A%0Aimport java.util.Date;%0A%0Aimport com.datastax.driver.core.BoundStatement;%0Aimport com.datastax.driver.core.Cluster;%0Aimport com.datastax.driver.core.PreparedStatement;%0Aimport com.datastax.driver.core.ResultSet;%0Aimport com.datastax.driver.core.Row;%0Aimport com.datastax.driver.core.Session;%0A%0Apublic class BulkInsert %7B%0A%09public static final int MAX_IDS = 200000;%0A%09public static final int MAX_COUNT = 20000;%0A%09public static final int THREAD_COUNT = 25;%0A%09public static Cluster cluster = null;%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09try %7B%0A%09%09%09cluster = Cluster.builder() // (1)%0A%09%09%09%09%09.addContactPoint(%22192.168.0.78%22)%0A%09%09%09%09%09.withClusterName(%22dcim-cluster%22).build();%0A%0A%09%09%09final int SLICE = MAX_IDS / THREAD_COUNT;%0A%09%09%09Thread%5B%5D threads = new Thread%5BTHREAD_COUNT%5D;%0A%09%09%09for (int i = 0; i %3C THREAD_COUNT; ++i) %7B%0A%09%09%09%09final int idx = i;%0A%09%09%09%09threads%5Bidx%5D = new Thread() %7B%0A%09%09%09%09%09public void run() %7B%0A%09%09%09%09%09%09executeInsert(cluster, idx * SLICE);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D;%0A%09%09%09%09threads%5Bidx%5D.start();%0A%09%09%09%7D%0A%09%09%09for (int i = 0; i %3C THREAD_COUNT; ++i) %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09threads%5Bi%5D.join();%0A%09%09%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D finally %7B%0A%09%09%09if (cluster != null)%0A%09%09%09%09cluster.close(); // (5)%0A%09%09%7D%0A%09%7D%0A%0A%09private static void executeInsert(Cluster cluster, final int startPos) %7B%0A%09%09Session session = cluster.connect(%22monitordb%22); // (2)%0A%0A%09%09ResultSet rs = session.execute(%22select release_version from system.local%22); // (3)%0A%09%09Row row = rs.one();%0A%09%09System.out.println(row.getString(%22release_version%22)); // (4)%0A%0A%09%09PreparedStatement ps = session.prepare(%22insert into history_ai(id, ts, value) values (?, ?, ?)%22);%0A%09%09for (int id = 20000; id %3C MAX_IDS; ++id) %7B%0A%09%09%09long ts1 = System.currentTimeMillis();%0A%09%09%09for (int i = 0; i %3C MAX_COUNT; ++i) %7B%0A%09%09%09%09BoundStatement bs = ps.bind(Long.valueOf(id), new Date().getTime(), Math.random());%0A%09%09%09%09session.execute(bs);%0A%09%09%09%7D%0A%09%09%09long ts2 = System.currentTimeMillis();%0A%09%09%09System.out.println(%22rows per second: %22 + MAX_COUNT / ((ts2 - ts1) / 1000.0));%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

add multiple threads.