comparison src/main/java/example/WriteThread.java @ 4:671a67571a48

fixed WriteThread
author one
date Thu, 06 Mar 2014 05:08:24 +0900
parents 37aab24020a0
children 24fca21a576e
comparison
equal deleted inserted replaced
3:37aab24020a0 4:671a67571a48
4 4
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; 5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; 6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; 7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
12 import junit.framework.Assert; 11 import junit.framework.Assert;
13 12
14 public class WriteThread extends Thread { 13 public class WriteThread extends Thread {
15 public static final String key = "name"; 14 public static final String key = "name";
16 public String valueString = "tatsuki"; 15 public String valueString = "tatsuki";
17 public ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); 16 public ByteBuffer value = ByteBuffer.wrap(valueString.getBytes());
18 Either<Error,JungleTreeEditor> either;
19 JungleTreeEditor editor;
20 JungleTree tree;
21 Jungle j; 17 Jungle j;
22 NodePath childPath; 18 NodePath childPath;
23 int roopCount; 19 int roopCount;
24 int num; 20 int num;
25 WriteThread(Jungle j,NodePath childPath , int roopCount , int num) { 21
22 WriteThread(Jungle j, NodePath childPath, int roopCount, int num) {
26 this.num = num; 23 this.num = num;
27 this.valueString = this.valueString + Integer.toString(num); 24 this.valueString = this.valueString + Integer.toString(num);
28 this.value = ByteBuffer.wrap(valueString.getBytes()); 25 this.value = ByteBuffer.wrap(valueString.getBytes());
29 this.roopCount = roopCount; 26 this.roopCount = roopCount;
30 this.j = j; 27 this.j = j;
31 this.childPath = childPath; 28 this.childPath = childPath;
32 } 29 }
33 30
34 public void run() { 31 public void run() {
35 tree = j.getTreeByName("tree");//名前を取得 32 JungleTree tree = j.getTreeByName("tree");// 名前を取得
36 editor = tree.getTreeEditor();//Treeのeditorを作成 33 Either<Error, JungleTreeEditor> either;
37 long t1 = System.currentTimeMillis();//時間の測定開始 34 System.out.println("roopCount = " + roopCount);
38 35 long t1 = System.currentTimeMillis();// 時間の測定開始
39 for(int count = 0 ; count < roopCount ; count++){ 36
40 do{ 37 for (int count = 0; count < roopCount; count++) {
41 either = editor.putAttribute(childPath,key,value); 38 do{
42 if(either.isA()){ 39 JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成
43 Assert.fail(); 40 either = editor.putAttribute(childPath, key, value);
44 } 41 if (either.isA()) {
45 editor = either.b(); 42 Assert.fail();
46 either = editor.success(); 43 }
44 editor = either.b();
45 either = editor.success();
47 }while(either.isA()); 46 }while(either.isA());
48 } 47 }
49 long t2 = System.currentTimeMillis(); 48 long t2 = System.currentTimeMillis();
50 System.out.println(num + "番目終わり" + (t2-t1) +"秒"); 49 System.out.println(num + "番目終わり" + (t2 - t1) + "秒");
51 } 50 }
52 } 51 }
53