Although this is primarily opinion based, I'm using the following conventions in my code:
- A Field or parameter that references an
Executor
or an ExecutorService
is named executor
or executorService
. The type of the executor should not be inferable by the name of the field as otherwise you cannot easily change the executor implementation afterwards.
- A class that implements
Runnable
or Callable
to realize a long-running operation usually gets the suffix Task
(like LoadTask
, ComputationTask
, ...). (As such an operation is not a thread, but is executed by a thread, and there is usually not a 1:1 mapping between threads and operations, it is wrong to call it thread).
This makes the code really readable and it does not make any assumption about thread usage, e.g.:
for (String fileName : fileNames) {
executor.execute(new LoadTask(fileName));
}
(This example might execute all load tasks in serial, in parallel or anything inbetween - according to the type of executor that's used).
One note about the word 'thread':
The word thread is not used anywhere except for the rare case where I have to either subclass from Thread
or create a field that references a (real) Thread
:
public class WorkerThread extends Thread { ... }
or:
Thread thread = Thread.currentThread();