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

[453 byte] By [Charalambosa] at [2007-11-27 5:38:08]
# 1

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);

}

}

Navy_Codera at 2007-7-12 15:11:15 > top of Java-index,Java Essentials,Java Programming...
# 2
Timer or TimerTask
camickra at 2007-7-12 15:11:15 > top of Java-index,Java Essentials,Java Programming...
# 3
> 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
Navy_Codera at 2007-7-12 15:11:15 > top of Java-index,Java Essentials,Java Programming...
# 4

> 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.

camickra at 2007-7-12 15:11:15 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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.

Navy_Codera at 2007-7-12 15:11:15 > top of Java-index,Java Essentials,Java Programming...