public void run() { try { for (int x = 0; ; x++) { data.put(new Integer(x)); System.out.println("Insertando " + x); } } catch (InterruptedException e) { } }
public <T> Future<T> enqueue(Callable<T> methodRequest) { final FutureTask<T> task = new FutureTask<T>(methodRequest) { @Override public void run() { try { super.run(); // 捕获所以可能抛出的对象,避免该任务运行失败而导致其所在的线程终止。 } catch (Throwable t) { this.setException(t); } } }; try { activationQueue.put(task); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return task; }