```java
@Test
public void test() {
Thread thread1 = new Thread(new Thread1());
Thread thread2 = new Thread(new Thread2());
try {
thread1.start();
thread2.start();
Thread.sleep(30000);
thread1.interrupt();
thread2.interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
class Thread1 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 1000; i++) {
aa(22);
}
}
}
class Thread2 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 1000; i++) {
aa(103);
}
}
}
public void aa(int a) {
Future<Integer> future = executorService.submit(new test(a));
try {
Integer result = future.get(5, TimeUnit.MILLISECONDS);
System.out.println("任务正常," + result);
} catch (InterruptedException | ExecutionException e) {
System.out.println("aaaa");
}catch (TimeoutException e){
future.cancel(true);
if (a==22){
System.out.println("任务超时"+a);
}
//future.cancel(true);
}
}
class test implements Callable<Integer>{
private int a;
public test(int a) {
this.a = a;
}
@Override
public Integer call() {
long time = System.currentTimeMillis();
while (!Thread.interrupted()){
if (a > 100) {
while (!Thread.currentThread().isInterrupted()){
for (int i=0;i<Integer.MAX_VALUE;i++){
new Integer(0);
}
}
}
if (a < 100) {
System.out.println("耗时2。。。。。。"+(System.currentTimeMillis()-time));
return a;
}
}
System.out.println("耗时。。。。。。"+(System.currentTimeMillis()-time));
throw new RuntimeException();
}
}
```