Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
guosean committed Jun 14, 2014
1 parent 6dfd83a commit 2b55247
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.2</version>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/concurrent/SimpleMicroBenchMark.java
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();
}

}

}
4 changes: 1 addition & 3 deletions src/main/java/com/sean/guava/TestCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import javax.management.timer.Timer;

import junit.framework.Assert;

import org.junit.Test;

import com.google.common.base.Ticker;
Expand All @@ -33,7 +31,7 @@ public long read() {
}
});
// Thread.currentThread().sleep(100);
Assert.assertEquals("cache", cache.getIfPresent("test"));
// Assert.assertEquals("cache", cache.getIfPresent("test"));
}

}
20 changes: 6 additions & 14 deletions src/main/java/com/sean/jdk/obj/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.sean.jdk.obj;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import lombok.Data;
import lombok.extern.log4j.Log4j;

public class Main {

public static void main(String[] args) {
Expand All @@ -24,7 +26,7 @@ public static void main(String[] args) {
System.out.println(it.next().getName());
}*/
System.out.println("=======================");
Iterable<Obj> it = new Iterable<Obj>() {
/* Iterable<Obj> it = new Iterable<Obj>() {
public Iterator<Obj> iterator() {
// TODO Auto-generated method stub
Expand All @@ -38,29 +40,19 @@ public Iterator<Obj> iterator() {
for (Obj obj : it) {
System.out.println(obj.getName());
}
*/
}

}

@Data
class Obj{

String name;


Person p;

public Obj(String name) {
this.p= new Person(name);
}

public String getName() {
return p.getName();
}

public void setName(String name) {
p.setName(name);
}

}

class Person{
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/sean/jdk8/MainClass.java
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);*/
}

}
1 change: 1 addition & 0 deletions src/test/java/com/sean/study/redis/TestSharedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import redis.clients.jedis.ShardedJedisPool;

public class TestSharedJedis {

@Test
public void testSlave(){
ShardedJedisPool sp = (ShardedJedisPool) BeanUtils.getBean("shardedPool");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Thu Jun 05 23:59:45 CST 2014
#Thu Jun 12 21:17:51 CST 2014
version=0.0.1-SNAPSHOT
groupId=com.sean
m2e.projectName=sean-study
Expand Down
2 changes: 1 addition & 1 deletion target/classes/META-INF/maven/com.sean/sean-study/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.2</version>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Binary file added target/classes/com/concurrent/Incrementable.class
Binary file not shown.
Binary file added target/classes/com/concurrent/LockingTest.class
Binary file not shown.
Binary file not shown.
Binary file added target/classes/com/concurrent/SynTest.class
Binary file not shown.
Binary file modified target/classes/com/sean/guava/TestCache$1.class
Binary file not shown.
Binary file modified target/classes/com/sean/guava/TestCache$2.class
Binary file not shown.
Binary file modified target/classes/com/sean/guava/TestCache.class
Binary file not shown.
Binary file modified target/classes/com/sean/jdk/obj/Main.class
Binary file not shown.
Binary file modified target/classes/com/sean/jdk/obj/Obj.class
Binary file not shown.
Binary file modified target/classes/com/sean/jdk/obj/Person.class
Binary file not shown.
Binary file added target/classes/com/sean/jdk8/MainClass.class
Binary file not shown.
Binary file modified target/test-classes/com/sean/study/redis/TestSharedJedis.class
Binary file not shown.

0 comments on commit 2b55247

Please sign in to comment.