e74f497834d833830e30c1d40df312d8357c687d
[IRC.git] / Robust / Transactions / TransactionalIO / src / TransactionalIO / benchmarks / MainforLocks.java
1
2 /*
3  * To change this template, choose Tools | Templates
4  * and open the template in the editor.
5  */
6
7 package TransactionalIO.benchmarks;
8
9 import TransactionalIO.core.TransactionalFile;
10 import java.io.FileNotFoundException;
11 import java.io.RandomAccessFile;
12 import java.util.logging.Level;
13 import java.util.logging.Logger;
14
15 /**
16  *
17  * @author navid
18  */
19 public class MainforLocks {
20     
21     public static void main(String args[]){
22         try {
23             RandomAccessFile file = new RandomAccessFile("/home/navid/randomwords.text", "rw");
24             benchmark.init();
25             long starttime = System.nanoTime();
26             
27       //      benchmark.filelock.writeLock().lock();
28             lockthread1 thread1 = new lockthread1(file, 'a');
29     //        benchmark.filelock.writeLock().unlock();
30             
31 //            benchmark.filelock.writeLock().lock();
32             lockthread1 thread2 = new lockthread1(file, 'b');
33   //          benchmark.filelock.writeLock().unlock();
34             
35      //       benchmark.filelock.writeLock().lock();
36             lockthread1 thread3 = new lockthread1(file, 'c');
37        //     benchmark.filelock.writeLock().unlock();
38             
39          //   benchmark.filelock.writeLock().lock();
40             lockthread1 thread4 = new lockthread1(file, 'd');
41          //   benchmark.filelock.writeLock().unlock(); 
42             
43          //   benchmark.filelock.writeLock().lock();
44             lockthread1 thread5 = new lockthread1(file, 'e');
45          //   benchmark.filelock.writeLock().unlock();
46             
47          //   benchmark.filelock.writeLock().lock();
48             lockthread1 thread6 = new lockthread1(file, 'f');
49          //   benchmark.filelock.writeLock().unlock(); 
50             
51          //   benchmark.filelock.writeLock().lock();
52             lockthread1 thread7 = new lockthread1(file, 'g');
53          //   benchmark.filelock.writeLock().unlock();
54             
55          //   benchmark.filelock.writeLock().lock();
56             lockthread1 thread8 = new lockthread1(file, 'h');
57          //   benchmark.filelock.writeLock().unlock();
58             
59          //   benchmark.filelock.writeLock().lock();
60             lockthread1 thread9 = new lockthread1(file, 'i');
61          //   benchmark.filelock.writeLock().unlock();
62             
63          //   benchmark.filelock.writeLock().lock();
64             lockthread1 thread10 = new lockthread1(file, 'j');
65          //   benchmark.filelock.writeLock().unlock();
66             
67          //   benchmark.filelock.writeLock().lock();
68             lockthread1 thread11 = new lockthread1(file, 'k');
69          //   benchmark.filelock.writeLock().unlock();
70             
71          //   benchmark.filelock.writeLock().lock();
72             lockthread1 thread12 = new lockthread1(file, 'l');
73          //   benchmark.filelock.writeLock().unlock();
74            
75          //   benchmark.filelock.writeLock().lock();
76             lockthread1 thread13 = new lockthread1(file, 'm');
77          //   benchmark.filelock.writeLock().unlock();
78             
79          //   benchmark.filelock.writeLock().lock();
80             lockthread1 thread14 = new lockthread1(file, 'n');
81          //   benchmark.filelock.writeLock().unlock(); 
82             
83          //   benchmark.filelock.writeLock().lock();
84             lockthread1 thread15 = new lockthread1(file, 'o');
85          //   benchmark.filelock.writeLock().unlock();
86             
87          //   benchmark.filelock.writeLock().lock();
88             lockthread1 thread16 = new lockthread1(file, 'p');
89          //   benchmark.filelock.writeLock().unlock();
90             
91          //   benchmark.filelock.writeLock().lock();
92             lockthread1 thread17 = new lockthread1(file, 'q');
93          //   benchmark.filelock.writeLock().unlock();
94             
95          //   benchmark.filelock.writeLock().lock();
96             lockthread1 thread18 = new lockthread1(file, 'r');
97          //   benchmark.filelock.writeLock().unlock();
98             
99          //   benchmark.filelock.writeLock().lock();
100             lockthread1 thread19 = new lockthread1(file, 's');
101          //   benchmark.filelock.writeLock().unlock();
102             
103          //   benchmark.filelock.writeLock().lock();
104             lockthread1 thread20 = new lockthread1(file, 't');
105          //   benchmark.filelock.writeLock().unlock();
106
107             thread1.join();
108             thread2.join();
109             thread3.join();
110             thread4.join();
111             thread5.join();
112             thread6.join();
113             thread7.join();
114             thread8.join();
115             thread9.join();
116             thread10.join();
117             thread11.join();
118             thread12.join();
119             thread13.join();
120             thread14.join();
121             thread15.join();
122             thread16.join();
123             thread17.join();
124             thread18.join();
125             thread19.join();
126             thread20.join();
127
128             long endttime = System.nanoTime();
129             System.out.println(endttime - starttime);
130             System.out.println((endttime - starttime) / 1000000);
131              int index =97;
132             for (int j = 0; j < 26; j++) {
133                 ((TransactionalFile)(benchmark.m.get(String.valueOf((char) (index+j))))).close();
134             }
135         } catch (InterruptedException ex) {
136             Logger.getLogger(MainforLocks.class.getName()).log(Level.SEVERE, null, ex);
137         } catch (FileNotFoundException ex) {
138             Logger.getLogger(MainforLocks.class.getName()).log(Level.SEVERE, null, ex);
139         }
140         
141     }
142 }