view 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
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) + "秒");
	}
}