Mercurial > hg > Members > tatsuki > jungle-bench
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle_core/AtomicBench.java @ 20:195c1a644550
benchmark add
author | tatsuki |
---|---|
date | Tue, 17 Mar 2015 15:37:19 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
19:17cc11b04157 | 20:195c1a644550 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle_core; | |
2 import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.lang.Integer;import java.lang.InterruptedException;import java.lang.Runtime;import java.lang.String;import java.lang.System;import java.util.concurrent.atomic.AtomicReference; | |
3 | |
4 /** | |
5 * Created by e115731 on 15/03/11. | |
6 */ | |
7 public class AtomicBench { | |
8 public static void main(String args[]) throws IOException { | |
9 Runtime rt = Runtime.getRuntime(); | |
10 int cpuNum = rt.availableProcessors(); | |
11 System.out.println("CPUCount = " + cpuNum); | |
12 File file = new File("strCount"); | |
13 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); | |
14 | |
15 AtomicReferenceTest ref = new AtomicReferenceTest(0); | |
16 | |
17 for (int count = 1; count <= cpuNum; count++) { | |
18 readAtomicReservableReferenceThread th[] = new readAtomicReservableReferenceThread[count]; | |
19 for (int tcount = 0; tcount < count; tcount++) { | |
20 th[tcount] = new readAtomicReservableReferenceThread(ref); | |
21 th[tcount].start(); | |
22 } | |
23 try { | |
24 java.lang.Thread.sleep(2000); | |
25 } catch (InterruptedException e) { | |
26 // TODO Auto-generated catch block | |
27 e.printStackTrace(); | |
28 } | |
29 long readCount = 0; | |
30 | |
31 for (int tcount = 0; tcount < count; tcount++) { | |
32 th[tcount].set(false); | |
33 System.out.println(th[tcount].get()); | |
34 readCount = readCount + th[tcount].get(); | |
35 } | |
36 | |
37 System.out.println("----------------------Thread Stop--------------------------------------------"); | |
38 | |
39 pw.println(count + " " + readCount); | |
40 System.out.println("ThreadTest count = " + count); | |
41 System.out.println("read count = " + (readCount)); | |
42 } | |
43 pw.close(); | |
44 System.out.println("-----------end--------------------------------------------------------"); | |
45 } | |
46 } |