commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1131328 - /commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java
Date Sat, 04 Jun 2011 06:41:01 GMT
Author: mturk
Date: Sat Jun  4 06:41:00 2011
New Revision: 1131328

URL: http://svn.apache.org/viewvc?rev=1131328&view=rev
Log:
Use monitor instead Thread.sleep for sync

Modified:
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java?rev=1131328&r1=1131327&r2=1131328&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSocketUtils.java
Sat Jun  4 06:41:00 2011
@@ -35,6 +35,8 @@ import org.testng.Assert;
 public class TestSocketUtils extends Assert
 {
 
+    private Object sync = new Object();
+
     @Test(groups = { "core" })
     public void boundServerSocket()
         throws IOException
@@ -75,6 +77,7 @@ public class TestSocketUtils extends Ass
     class Worker extends Thread
     {
         ServerSocket ss;
+        
         public Worker(ServerSocket ss)
         {
             this.ss = ss;
@@ -82,6 +85,9 @@ public class TestSocketUtils extends Ass
 
         public void run() {
             try {
+                synchronized(sync) {
+                    sync.notifyAll();
+                }
                 Socket s = ss.accept();
                 assertNotNull(Sockets.getFileDescriptor(s));
             } catch (Exception x) {
@@ -98,8 +104,9 @@ public class TestSocketUtils extends Ass
         Worker w = new Worker(ss);
         w.start();
         try {
-
-            Thread.sleep(500);
+            synchronized(sync) {
+                sync.wait();
+            }
         } catch (InterruptedException x) {
             // Ignore
         }
@@ -128,8 +135,9 @@ public class TestSocketUtils extends Ass
         Worker w = new Worker(ss);
         w.start();
         try {
-
-            Thread.sleep(500);
+            synchronized(sync) {
+                sync.wait();
+            }
         } catch (InterruptedException x) {
             // Ignore
         }



Mime
View raw message