Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4211692
Votes 2
Synopsis thread.interrupt does not work as expected with some versions of the VM.
Category java:classes_net
Reported Against 1.1.6
Release Fixed
State 11-Closed, duplicate of 4154947, bug
Priority: 4-Low
Related Bugs 4154947 , 4403952
Submit Date 15-FEB-1999
Description




Problem description:
 
I try to unblock a call to ServerSocket.accept() by calling thread.interrupt from a different thread.

I create a thread that does a call to ServerSocket.accept(), and after 5 seconds the main thread try to interrupt the accept call by calling thread.interrupt. 

This works on Solaris using the jdk, and it works on NT using  customer  VJ++ 6.0.

It does NOT work using the jdk1.1.6 from javasoft on NT, and it does NOT work using Inprise JBuilder2 on NT. 

I've added a call to setSoTimeout, but it makes no difference. In both cases the program hangs until the timeout occurs on the ServerSocket.



Exact steps to reproduce the problem:
-> Compile and run the included source code.

Java SOURCE CODE that demonstrates the problem:

BEGIN SOURCE:

import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.io.InterruptedIOException;

class TestSocket implements Runnable
{
  public TestSocket() throws IOException
    {
      srvsock = new ServerSocket(3000);
      srvsock.setSoTimeout(20000);  // I don't need this on Solaris
                                   // and it does not help on NT ?
    }

  public void run()
    {
      try
      {
	thread = Thread.currentThread();

	System.out.println("Waiting for connections...");
      
	Socket s = srvsock.accept();

	System.out.println("Connection accepted.");
      }
      catch (InterruptedIOException e)
      {
	System.out.println("Accept interrupted.");
	
      }
      catch (IOException e)
      {
	System.out.println("IOException!");
      }
      finally 
      {
	System.out.println("Terminating.");
      }
    }

  public void stop()
    {
      if (thread != null)
	thread.interrupt();
    }
  
  
  private ServerSocket srvsock;
  private Thread thread;
  
  
}



public class TestInterrupt 
{

  public TestInterrupt()
  {
  }

  public static void main(String[] args)
    {
      try 
      {
	TestSocket ts = new TestSocket();
	
	Thread t = new Thread(ts);
      
	t.start();
      
	System.out.println("Going to sleep...");
	
	Thread.currentThread().sleep(5000);
      
      
	System.out.println("Waking up, trying to stop other thread gracefully");
      
	ts.stop();

	t.join();
      }
      catch (Exception e)
      {
	System.out.println(e.toString());
      }
      finally 
      {
	System.out.println("That's it! Goodbye.");
      }
      
    }
}

END SOURCE.
(Review ID: 42996)
======================================================================
Work Around




Not known.
======================================================================
Evaluation
N/A
Comments
  
  Include a link with my name & email   

Submitted On 23-JUL-1999
froh
Isnīt this a duplicate of 4154947 ?



PLEASE NOTE: JDK6 is formerly known as Project Mustang