If you don't want something big and fancy like ^ that guy suggested

, I would use the FPGA time method in the Utility class.
Code:
long millisecondsToRun = 1000; // This should run 1000ms = 1 s.
long initTime = Utility.getFPGATime();
while (Utility.getFPGATime() - initTime <= millisecondsToRun){
// Place your code here.
}
What this does is:
Utility.getFPGATime() gives you a time in milliseconds, say 123400 ms. Now, you want to run your code for a continuous 2 seconds. You would then set the while loop to run your code UNTIL 2 seconds or 2000 ms has passed. So, the loop would be to run until the FPGA time is equals or greater than 125400 ms. And then, it stops running because the conditional is no longer true.