-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guosean
committed
Jun 14, 2014
1 parent
6dfd83a
commit 2b55247
Showing
20 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.concurrent; | ||
|
||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
public class SimpleMicroBenchMark { | ||
|
||
public static void main(String[] args) { | ||
long synchTime = test(new SynTest()); | ||
long lockTime = test(new LockingTest()); | ||
System.out.println("syn:"+synchTime); | ||
System.out.println("lock:"+lockTime); | ||
System.out.printf("lock/syn = %1$.3f",(double)lockTime/(double)synchTime); | ||
} | ||
|
||
static long test(Incrementable incr){ | ||
long start = System.nanoTime(); | ||
for(int i=0; i< 10000000L; i++){ | ||
incr.increment(); | ||
} | ||
return System.nanoTime() - start; | ||
} | ||
|
||
} | ||
|
||
abstract class Incrementable{ | ||
protected long counter = 0; | ||
public abstract void increment(); | ||
} | ||
class SynTest extends Incrementable{ | ||
|
||
@Override | ||
public synchronized void increment() { | ||
counter++; | ||
} | ||
|
||
} | ||
|
||
class LockingTest extends Incrementable{ | ||
private Lock lock = new ReentrantLock(); | ||
@Override | ||
public void increment() { | ||
lock.lock(); | ||
try{ | ||
counter++; | ||
}finally{ | ||
lock.unlock(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sean.jdk8; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class MainClass { | ||
|
||
public static void main(String[] args) { | ||
// List<String> names = Lists.; | ||
List<String> names = new ArrayList<String>(); | ||
names.add("Name1"); | ||
names.add("Name2"); | ||
System.out.println(names); | ||
/*List<String> lowercaseNames = names.stream().map((String name) -> { | ||
return name.toLowerCase(); | ||
}).collect(Collectors.toList()); | ||
System.out.println(lowercaseNames);*/ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
target/classes/META-INF/maven/com.sean/sean-study/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
target/test-classes/com/sean/study/redis/TestSharedJedis.class
Binary file not shown.