package org.kne.cloud.network;

import java.io.Closeable;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class TimeoutTimer extends Timer {
	public TimeoutTimer() {
		super( "接收超时计时器线程", true);
	}

	public TimerTask createTimeOutTask(Closeable res,long timeout) {
		TimerTask tt;
		if(timeout>0) {
			tt=new TimerTask() {
				
				@Override
				public void run() {
					try {
						res.close();
						System.out.println("timeout");
					} catch (IOException e) {
					}
				}
			};
		}else {
			tt=null;
		}
		if(tt!=null)
		schedule(tt, timeout);
		return tt;
	}
}
