threads - use them as much as you can

James Hague <>
Mon Nov 27 16:36:28 CET 2000

I see the Java warning as more along the lines of "don't use threads when
you don't really need them" more than "don't ever use threads."  For
example, if you were writing code to process user input for a window full
of controls, you could:

1. Model each control as a thread/process.
2. Don't use threads and simply scan through a list of controls when input
is detected.

There's a certain prettiness to #1, but if the controls don't really
operate in an asynchronous manner, then #2 is perfectly valid and simpler
in most languages.

I think that Erlang comes into its own when you have an application that's
similar to an operating system, with tasks starting and stopping
constantly, each doing something fairly independent of the rest of the
tasks.  A web server is a good example, as are telephone exchanges.  In the
window example above, there aren't lots of independently executing tasks,
but rather a collection of object-like entities where the benefit of
separation into processes is one of dividing a large global state into
smaller, more clearly defined spaces.  But it isn't clear that processes
offer much over objects in this case, especially as processes have more
ovehead (message passing vs. subroutine calls).

I expect that most Java progammers who use threads are using a only handful
of threads, possibly only two.  The exceptions are those unfortunate Java
programmers trying to write web servers and such :)


More information about the erlang-questions mailing list