Code example for ServerSocket

Methods: accept

 * Test that Socket.close called on another thread interrupts a thread that's blocked doing 
 * network I/O. 
public class ConcurrentCloseTest extends junit.framework.TestCase {
    public void test_accept() throws Exception { 
        ServerSocket s = new ServerSocket(0);
        new Killer(s).start();
        try { 
            fail("accept returned!");
        } catch (SocketException expected) {
            assertEquals("Socket closed", expected.getMessage());
    public void test_connect() throws Exception { 
        StuckServer ss = new StuckServer();
        Socket s = new Socket();
        new Killer(s).start();
Connect your IDE to all the code out there  Get Codota for Java