I need to do a program with java that creates an object every 30 seconds and puts it in a queue and then does some operations with them. I had thought about creating the object and that creating it would also create a kind of counter, so that when it reaches 30 seconds, another object is created until you have 100.
I tried something with System.currentTimeMillis (); but I can not think of how to make it count for 30 seconds and then do other operations.
I've been looking and I've tried this:
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
do {
Camion c = new Camion();
A.add(c);
System.out.println(c.toString());
}while(A.size()<100);
}
};
timer.schedule(task, 30000);
But it's not what I wanted, this does it all at once at 30 seconds.