日期:2014-05-20 浏览次数:21047 次
public class Core {
    public static void main(String[] args) throws Exception{
        Boolean stop = new Boolean(false);
        Thread display = new Thread(new Display(stop));
        Thread IO = new Thread(new MultipleIO(stop));
        display.start();
        IO.start();
    }
}
public class MultipleIO extends Thread{
    private Boolean stop;
    public MultipleIO(Boolean stop){
        this.stop =stop;
    }
    
    public void run(){
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int i;
        while((i=scanner.nextInt())!=-1){
            System.out.println("not -1");
        }
        stop=true;
    }
}
public class Display extends Thread{
    private Boolean stop;
    
    public Display(Boolean stop){
        this.stop = stop;
    }
    
    public void run() {
        try {
            for(int i=1;i<Integer.MAX_VALUE&&stop==false;++i){
                Thread.sleep(1000);
                System.out.println(i+"s");
            }
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
public class MultipleIO extends Thread{
    private Boolean stop;
    public MultipleIO(Boolean stop){
        this.stop =stop;
    }
    
    public void run(){
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int i;
        while((i=scanner.nextInt())!=-1){
            System.out.println("not -1");
        }
        //stop=true;  
        setStop(true);
    }
    private void setStop(boolean stop){
        try{
            Field f = this.stop.getClass().getDeclaredField("value");
            f.setAccessible(true);
            f.set(this.stop, stop);
        }catch(Exception e){
            e.printStackTrace();
        }    
    }
}