Triggering timers...
hello everyone,
What i want to do is the following:
In an object A i create an object B and add it in an arraylist of another object C. After some specific time expires, i want to remove object B from the arraylist of C and put in another arraylist of another object. Anybody has any ideas how can this be done? Can a timer be triggered somehow in object C when something is added in its arraylist?
...hope i am not to abstract
Just try adding the conditional logic to a public method in your ObjectC class.
here's an example (doesn't compile)
class ObjectA {
public static void main(String[] argv) {
ObjectB b = new ObjectB();
ObjectC c = new ObjectC();
c.addToList(b);
}
}
class ObjectB {
public ObjectB() { }
}
class ObjectC {
private ArrayList<ObjectB> objects;
public ObjectC() {
objects = new ArrayList<ObjectB>();
}
public void addToList(ObjectB b) {
if( my trigger condition is met )
objects.remove(the old item);
else
objects.add(b);
}
}
> Timer or TimerTaskEither of those would work if it were at a regular interval, but my understanding was that he needed something to happen based upon an event that may happen at very irregular intervals - such as when something was added to an array (per the OPs
> but my understanding was that he needed something to happen
> based upon an event that may happen at very irregular intervals - such as when something was added to an array
So you start a separate Timer every time an Object is added to the array. The Timer will only affect that object. Thats my understanding. If its wrong then the OP can reply. I don't waste time trying to interpret less than ideal specs.
> So you start a separate Timer every time an Object is
> added to the array. The Timer will only affect that
> object. Thats my understanding. If its wrong then the
> OP can reply. I don't waste time trying to interpret
> less than ideal specs.
Right, right.