Mercurial > hg > Members > tatsuki > jungle-bench
view src/main/java/example/WriteThread.java @ 5:24fca21a576e
add Read thread source
author | Kanagawa TATSUKI <tatsuki@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 30 Mar 2014 23:21:59 +0900 |
parents | 671a67571a48 |
children | 442463aa27e5 |
line wrap: on
line source
package example; import java.nio.ByteBuffer; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import junit.framework.Assert; public class WriteThread extends Thread { public static final String key = "name"; public String valueString = "tatsuki"; public ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); Jungle j; NodePath childPath; int roopCount; int num; WriteThread(Jungle j, NodePath childPath, int roopCount, int num) { this.num = num; this.valueString = this.valueString + Integer.toString(num); this.value = ByteBuffer.wrap(valueString.getBytes()); this.roopCount = roopCount; this.j = j; this.childPath = childPath; } public void run() { JungleTree tree = j.getTreeByName("tree");// 名前を取得 Either<Error, JungleTreeEditor> either; System.out.println("roopCount = " + roopCount); long t1 = System.currentTimeMillis();// 時間の測定開始 for (int count = 0; count < roopCount; count++) { do { JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 either = editor.putAttribute(childPath, key, value); if (either.isA()) { Assert.fail(); } editor = either.b(); either = editor.success(); } while (either.isA()); } long t2 = System.currentTimeMillis(); System.out.println(num + "番目終わり" + (t2 - t1) + "秒"); } }