Hello, experts, i have an problem about interrupt()

here is my code, i wanna test what the client requested/posted ,but it seems that i can't interreput other thread which in io blocked ,how can i solve this? thanks!
package yestalk.playground;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class STC
     public static void main (String[] args) throws Exception
          ServerSocket ss  = new ServerSocket(8889);
          int i = 0;
          long start;
          while (true)
               System.out.println("\r\n------------     "+ (i++));
               Socket so = ss.accept();
               InputStream ins = so.getInputStream();
               InputStreamReader insr = new InputStreamReader( ins, "UTF-8");
               int c;
               try
                    start = System.currentTimeMillis();
                    while((c = insr.read()) != -1)
                         System.out.print((char)c);
                         new Thread(new STC.TimerBreaker(Thread.currentThread(),start,5000)).start();
               }catch(Exception e)
                    System.out.println("timer breaker interrupted me:     "+e.getMessage());
               }finally
                    insr.close();
                    so.close();
     static class TimerBreaker implements Runnable
          long start;
          long interval;
          long current;
          Thread ct;
          public TimerBreaker (Thread t,long start,long interval)
               this.ct=t;
               this.start=start;
               this.interval=interval;
          public void run ()
               while(true)
                    try
                         Thread.sleep(500);
                         current = System.currentTimeMillis();
                         System.out.println((current-start)>interval);
                         if((current-start)>interval)
                              ct.interrupt();
                              System.out.println(" is read thread Interrupted:     "+ct.isInterrupted());
                              System.out.println(" is read thread still alive:     "+ct.isAlive());
                              break;
                    catch (Exception e)
                         System.out.println("timeBreaker exception:     "+e.getMessage());
               System.out.println("timer thread breaked!!!!!!!!!!!!!!!!!!!!!!!");
}i am waiting on board,thanks very much.

sorry, i change my code ,let it more clear.i wanaa see what did the http client requested/posted, but i don't wan't parse the http protocol to know when to close connection precisely,so i think 5s is enough to read all client requested/posted,so i would like "continue read" but close connection in 5s. and the server should continue listening....
but as you say that : java.net.Socket I/O methods aren't specified to be interruptible.
and i see the doc :
public void interrupt() // it's not static method, so i think it cant apply to an instance.
Unless the current thread is interrupting itself, which is always permitted, the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.
does interrupt other Thread use another Thread is a proper act?
how can't i achieve my objective? thanks very much.
and , sorry: i change my code three time. now it is not try to establish a new thread every char read.
package yestalk.playground;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class STC
     public static void main (String[] args) throws Exception
          ServerSocket ss  = new ServerSocket(8889);
          int i = 0;
          long start;
          while (true)
               System.out.println("\r\n------------     "+ (i++));
               Socket so = ss.accept();
               InputStream ins = so.getInputStream();
               InputStreamReader insr = new InputStreamReader( ins, "UTF-8");
               int c;
               try
                    new Thread(new STC.TimerBreaker(Thread.currentThread(),5000)).start();
                    while((c = insr.read()) != -1)
                         System.out.print((char)c);
               }catch(Exception e)
                    System.out.println("timer breaker interrupted me:     "+e.getMessage());
               }finally
                    insr.close();
                    so.close();
     static class TimerBreaker implements Runnable
          long interval;
          Thread ct;
          public TimerBreaker (Thread t,int interval)
               this.ct=t;
               this.interval=interval;
          public void run ()
                    try
                         Thread.sleep(interval);
                         ct.interrupt();
                         System.out.println(" is read thread Interrupted:     "+ct.isInterrupted());
                         System.out.println(" is read thread still alive:     "+ct.isAlive());
                    catch (Exception e)
                         System.out.println("timeBreaker exception:     "+e.getMessage());
}Edited by: Johnny on Oct 19, 2008 11:18 PM

Similar Messages

Maybe you are looking for

  • Authorization check for Open and Close Periods ( OB52)

    Dear Experts,                        We have created ZOB52 for Opening and closing periods. This is replica of Tcode: OB52 with some other developments that we required. Here for resticting user I had tried authorization Object: F_BKPF_BUP for partic

  • Data recovery help and options

    If you don't want to read the entire diatribe, please answer:  Any suggestions as to which data recovery app is appropriate for a ThunderBolt Seagate GoFlex 1TB?  It's been 21 hours, should I stop and restart First Aid? I have a MBP15R that is about

  • Sale Order costing - Updation of SD conditions

    Hi SAP Gurus, I would like to know how the cost calculated in Sale Order costing is updated in VPRS Condition type Pricing Procedure. Where do we do the settings for updation of the same You Valuable answer would be suitably rewarded Thanks in Advanc

  • Cisco ISE integration with AD fails

    Cisco ISE Ver: 1.1.2.145 Windows : Win 2003 Server I am attempting to integrate ISE with AD, but ISE won't join AD and joining attempts fails, though I am able to add same domain as external LDAP identity store ? 1.user used to join the domain has ad

  • Newbie ? - Error Opening Database After Recovery

    Hi All- I'm new to Oracle and am using 9i - I'm working on cloning our Production db for a Test db. I shutdown the Production db and copied all the files from that db into my Test db - I then started my Test db and recovered it. I am now trying to OP