Merge branch 'master' of github.com:UCNProf/KAJE-JAVA
This commit is contained in:
@@ -48,7 +48,7 @@ public class ClassicIoBuffered {
|
||||
int lines = lineCount("input.txt", true);
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lines));
|
||||
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " ");
|
||||
System.out.println("Time to complete: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ClassicIoManBuffered {
|
||||
int lines = lineCount("input.txt", true);
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lines));
|
||||
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " ");
|
||||
System.out.println("Time to complete: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ClassicIoUnbuffered {
|
||||
int lines = lineCount("input.txt", true);
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lines));
|
||||
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
System.out.println("Time to complete: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ClassicIoWholeFile {
|
||||
int lines = lineCount("input.txt", true);
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lines));
|
||||
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " ");
|
||||
System.out.println("Time to complete: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class NioLineCount {
|
||||
int lines = lineCount("input.txt", true);
|
||||
long stopTime = System.nanoTime();
|
||||
System.out.println("Lines: " + String.valueOf(lines));
|
||||
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
System.out.println("Time to complete: " + (stopTime - startTime - dryRun) + " " + dryRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
//
|
||||
// java application to demonstrate
|
||||
// use of semaphores (Locks)
|
||||
//
|
||||
// The Semaphore constructor takes one argument: The number of permits!
|
||||
// Every acquire granted will decrease the number of available permits by 1.
|
||||
// Every release of an acquired semaphore will increase the number of permits.
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@@ -12,9 +16,9 @@ public class SemaphoreDemo
|
||||
public static void main(String args[]) throws InterruptedException
|
||||
{
|
||||
// creating a Semaphore object
|
||||
// A 1 means that you are allowed 1 write to start with
|
||||
// Granting 1 permit: You may write one object to the buffer
|
||||
Semaphore semPro = new Semaphore(1);
|
||||
// A 0 means that you are not allowed to read (as nobody has yet written to the buffer)
|
||||
// Granting 0 permits: Thou shallt not read what hasn't yet been written! (as nobody has yet written to the buffer)
|
||||
Semaphore semCon = new Semaphore(0);
|
||||
|
||||
// creating two threads named "Producer" and "Consumer"
|
||||
|
||||
Reference in New Issue
Block a user