I have a function say Foo()...My requirement to run some function for specific time and force it to return value within that given time.For eg if i run this function for 100 ms then no matter how many numbers are added in List listofnumbers whitin 100ms it should return those values.I have seen Timer as one solution but Timer or TimerTask has API to schedule task once every some seconds.What i want is to run function only and return whatever value it has wihtin given time.
foo()
{
List lisof numbers
for(int i=0;i<somenumber;i++)
{
listofnumbers.add(i);
}
return listofnumbers }