While I am reasonably familiar with the use of threads in Java
( or at least the syntax ), the question is exactly when should
they should be used and in particular how 'fast' things must be
before you use them ? I had thought they were used to prevent
various runs of the same job interfering with each other.
The question is whether jobs involving folks 'doing stuff for real'
fall into this category ?
The program in question involves the design of a game where
( to oversimplify ) a dozen people are running around a lot.
Now does THAT look like a case that needs threads ?
However fast they happen to run, could they all not be,
say, instances of a particular class ?

A guy I know ( and who is better than I am in Java terms )
had to write this program and insists threads are both
obvious and necessary here. One of us is missing something.

Serious opinions welcomed.

5 Years
Discussion Span
Last Post by frank33

I'd use a Thread to move processing off of the EDT's thread for one example.
Another use would be when you want to be able to get data from a file or the internet and at the same time have a responsive GUI that the user can interact with.
Another would be on a server so it can handle multiple clients in parallel instead of serially.

Edited by NormR1


Yes, thanks, but the question is whether a thread is necessary in a case
of the activity of HUMANS ( as opposed to OTHER RUNNING JOBS ) ?
Are humans able to run so fast as to NECESSITATE threads on a Java program
to monitor their behavior ?


I suspect that every threaded implementation could be replaced by a sufficiently cunning non-threaded version, so the question is "when are threads useful?" rather than "when are they necessary?".
For your people running about it may make sense to have one thread for each person in that the code is simpler - for example you can simply wait for the person to run into a wall without having to worry about ether some other person may run into a wall sooner.
In short, threads are typically useful when you want one thing to carry on while another is waiting for something. Speed doesn't really come into it.

Edited by JamesCherrill: typo


Thanks for clearing that up.

Here's why I asked : the program I briefly described was written by a guy I know as part of a job application. He was rejected for 'inelegance'. Seemed to me obvious enough that it was a question of using threads ( or not ). Then again even if they are 'useful', as you say, maybe it is subjective question of them 'looking good'.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.