code: public static void execute(Thread thread, long timeout) {
  	thread.start();
  
  	try {
  	    thread.join(timeout);
  	} catch (InterruptedException e) {
  	    // Should not be interrupted normally.
  	}
  
  	if (thread.isAlive()) {
  	    thread.interrupt();
  	}
      }
docs: Executes the thread with specified timeout.
  
  @param thread
  - the thread to execute.
  @param timeout
  - the timeout.