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