Created
November 9, 2012 06:05
-
-
Save namkyu/4043992 to your computer and use it in GitHub Desktop.
synchronized test1
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
public class SyncTest { | |
private static SyncTarget target; | |
@BeforeClass | |
public static void init() { | |
target = new SyncTarget(); | |
System.out.println("init"); | |
} | |
@Test | |
public void threadLockTest1() { | |
for (int i = 0; i < 5; i++) { | |
new Thread() { | |
@Override | |
public void run() { | |
target.test1(); | |
}; | |
}.start(); | |
} | |
} | |
@Test | |
public void threadLockTest2() { | |
for (int i = 0; i < 5; i++) { | |
new Thread() { | |
@Override | |
public void run() { | |
target.test2(); | |
}; | |
}.start(); | |
} | |
} | |
@Test | |
public void threadLockTest3() { | |
for (int i = 0; i < 5; i++) { | |
new Thread() { | |
@Override | |
public void run() { | |
target.test3(); | |
}; | |
}.start(); | |
} | |
} | |
public static class SyncTarget { | |
public void test1() { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("test1(), threadName=" + Thread.currentThread().getName()); | |
} | |
public synchronized void test2() { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("test2(), threadName=" + Thread.currentThread().getName()); | |
} | |
public synchronized void test3() { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("test3(), threadName=" + Thread.currentThread().getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment