| View previous topic :: View next topic |
| Author |
Message |
anna_a
Joined: 02 Jul 2009 Posts: 9
|
Posted: Fri Jul 03, 2009 10:53 am Post subject: Help needed regarding ArrayList or similar containing activities to be executed |
|
|
Hi,
I want to create some kind of list, array or similar that contains activities (that are described in separate classes) that are supposed to be executed in a consecutive order.
For example we could have activities/classes "Warming up", "Running", and "Stretching" - what I want is for these to be gathered together somehow, so that I from the main method can extract the first item (warming up) of the container/list/array (or whatever it might be) and then execute that activity by creating the constructor of that class, and after that's been done move forward to the next activity, execute it, and so on. Any tips on how to achieve this would be greatly appreciated! _________________ anna |
|
| Back to top |
|
 |
Franz Posted via mailing list.
|
Posted: Sat Jul 04, 2009 7:15 am Post subject: Help needed regarding ArrayList or similar containing activities to be executed |
|
|
Hello,
anna_a schrieb:
| Quote: | I want to create some kind of list, array or similar that contains activities (that are described in separate classes) that are supposed to be executed in a consecutive order.
For example we could have activities/classes "Warming up", "Running", and "Stretching" - what I want is for these to be gathered together somehow, so that I from the main method can extract the first item (warming up) of the container/list/array (or whatever it might be) and then execute that activity by creating the constructor of that class, and after that's been done move forward to the next activity, execute it, and so on. Any tips on how to achieve this would be greatly appreciated!
|
if you really need the constructor of the classes to be executed, you
can use s.th like:
List<Class> l = new ArrayList<Class>();
l.add(A.class);
l.add(B.class);
for (Class c : l) {
c.newInstance();
}
Regards
franz |
|
| Back to top |
|
 |
areeda
Joined: 28 Aug 2008 Posts: 88
|
Posted: Sat Jul 04, 2009 7:35 pm Post subject: Re: Help needed regarding ArrayList or similar containing activities to be executed |
|
|
| anna_a wrote: | Hi,
I want to create some kind of list, array or similar that contains activities (that are described in separate classes) that are supposed to be executed in a consecutive order.
For example we could have activities/classes "Warming up", "Running", and "Stretching" - what I want is for these to be gathered together somehow, so that I from the main method can extract the first item (warming up) of the container/list/array (or whatever it might be) and then execute that activity by creating the constructor of that class, and after that's been done move forward to the next activity, execute it, and so on. Any tips on how to achieve this would be greatly appreciated! |
I hope I'm not muddying the waters but I'm a bit confused at what you're trying to do.
If this is a simple single thread linear operation why not create and use the classes as you determine the need.
If on the other hand one task is generating the request and another is executing them, a queue or a blocking queue might be a better structure.
See
http://java.sun.com/docs/books/tutorial/collections/interfaces/queue.html
and
http://www.developer.com/java/ent/article.php/3645111
Joe |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|