Efficiency/Design questions

Hey,

If I have three classes, one which uses threads to run the other two classes (say a and b), but b cannot run until a has finished, is it better to have the first thread call the second thread and then terminate, or to simply have the first thread finish with a, and then go straight into b without using another thread?

Secondly, if I have a method in a class that receives an ArrayList from one class, and then calls another class, passing this ArrayList as a parameter (without modifying it), is it better to import java.util.ArrayList simply for this purpose, or to have it receive objects and then cast them back to ArrayLists where necessary (preventing the import)?

Thanks for any advice.

[724 byte] By [abu5ea] at [2007-11-26 21:10:23]
# 1

If you want to do a, then b, there is absolutely no point in running a and b in separate threads.

And if your design calls for passing ArrayLists as parameters then your implementation should do that too. Writing casts introduces possible errors into your program, and there is no point in doing that just to avoid one line of code.

DrClapa at 2007-7-10 2:47:02 > top of Java-index,Java Essentials,Java Programming...
# 2

> ArrayLists where necessary (preventing the import)?

What DrClap said. In addition, importing has ZERO effect at runtime. It does not make the class file bigger. It does not make the code run slower. You could import every single class you can see, or nothing at all, and the generated bytecode would be the same.

Importing does not affect the class file or the runtime at all. All it does is let you use shorter class identifiers, saving typing and keeping your code less cluttered. It just tells the compiler that, for instance, when you say "List" you actually mean "java.util.List."

jverda at 2007-7-10 2:47:02 > top of Java-index,Java Essentials,Java Programming...