Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ADded totally unrelated testcase ;)

  • Loading branch information...
commit fc31df385189c25de9e30d923e7b2ab28bc33a19 1 parent 96b6912
@krosenvold authored
View
60 src/test/java/org/rosenvold/spring/convention/ReentrantLockTest.java
@@ -0,0 +1,60 @@
+package org.rosenvold.spring.convention;
+
+import org.junit.Test;
+
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ReentrantLockTest {
+
+ private final ReentrantLock lock = new ReentrantLock();
+ private final Condition testSessionAvailable = lock.newCondition();
+
+ @Test
+ public void testTheLock() throws InterruptedException {
+ OtherThread otherThread = new OtherThread();
+ try {
+ lock.lock();
+
+ otherThread.start();
+
+ Thread.sleep(200);
+ testSessionAvailable.signal();
+ Thread.sleep(100);
+
+ } finally {
+ lock.unlock();
+ }
+
+ otherThread.join();
+
+ }
+
+
+ class OtherThread extends Thread{
+
+ OtherThread() {
+ super("OtherThread");
+ }
+
+ @Override
+ public void run() {
+ long start = System.currentTimeMillis();
+ try {
+ lock.lock();
+
+ Thread.sleep(400);
+ //testSessionAvailable.await();
+
+ } catch (InterruptedException e) {
+ } finally {
+ lock.unlock();
+ }
+ }
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.