私はこれを読みました
メソッドが正常に完了したか、中断されたかをどのように確認しますか?
編集:質問をより明確かつ具体的にするために、以下は私のコードです..test.javaファイルを実行してそのランタイムを取得したい..ただし、1秒以上かかる場合はエラーメッセージを表示して停止したいそれ自体があります..
public class cl {
public static void main(String args[])throws IOException
{
String s=null;
Process p=Runtime.getRuntime().exec("javac C:\\Users\\Lokesh\\Desktop\\test.java");
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
Timer timer=new Timer(true);
InterruptTimerTask interruptTimerTask=new InterruptTimerTask(Thread.currentThread());
timer.schedule(interruptTimerTask,1);
try{
Runtime.getRuntime().exec("java C:\\Users\\Lokesh\\Desktop\\test");
}
catch (Exception e)
{
e.printStackTrace();
}
finally {
timer.cancel();
}
}
static class InterruptTimerTask extends TimerTask {
private Thread thread;
public InterruptTimerTask(Thread thread)
{
this.thread=thread;
}
@Override
public void run()
{
thread.interrupt();
}
}
}