```
public class Ex4 extends Thread {
  boolean ans;
  boolean change=false;

  public boolean isPrime(long n, double maxTime) throws RuntimeException {
    final Thread a;
    Thread b;
    final RuntimeException e;
    final long num = n ;
    final double mtime = maxTime;
    a = new Thread(){
        public void run(){
                try{
                    ans = Ex4_tester.isPrime(num);
                    change=true;
                }
                catch ( RuntimeException exp){
                    throw exp;
                };
            }
    };
    a.start();
    try {
        sleep((long)mtime);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    if(a.isAlive()){
        a.interrupt();
    }
    if(a.isInterrupted()){
        throw new RuntimeException("time for check exceeded");
    }
    return ans;
  }
}

```

all works fine, except sometimes Ex4\_tester.isPrime goes into infinite loop (its ok, it should do that).
the problem that even though the thread gets interrupted the process keeps running and the thread doesnt actually stop