view src/main/java/example/WriteThread.java @ 3:37aab24020a0

thread test
author Kanagawa TATSUKI <tatsuki@ie.u-ryukyu.ac.jp>
date Thu, 06 Mar 2014 04:17:40 +0900
parents
children 671a67571a48
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.store.impl.DefaultNodePath;
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());
	Either<Error,JungleTreeEditor> either;
	JungleTreeEditor editor;
	JungleTree tree;
	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() {
	tree = j.getTreeByName("tree");//名前を取得
	editor = tree.getTreeEditor();//Treeのeditorを作成
	long t1 = System.currentTimeMillis();//時間の測定開始
	
	for(int count = 0 ; count < roopCount ; count++){
		do{
			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) +"秒");
	}
}