Task-based vs actor-based thread usage

Last week I was reading “Concurrent Programming in Java” from Doug Lea in the train to my work. One of the topics I was reading was chapter 4 “Creating threads” and a distinction was made between 2 different approaches for using threads:

  1. task-based: when a task needs to be executed asynchronously on a different thread. An example of this is the execution of a batch process started by a Servlet thread when a user pressed a button. After the task is executed, it can be discarded. The Executor was made for task based problems although it lacks some functionality for blocking when a task can’t be processed.
  2. actor-based: when a thread runs as an automonous process (the actor) and is able to react on events from the environment. An example of an acter based design is a thread that runs a server socket. When a client request is accepted, the server socket processes the request and waits for the next request.

It is possible to combine the actor and task-based styles, e.g. as soon as a socket-request from a client is accepted, the task of processing this request could be executed asynchronously on a different thread (task based) using an Executor to keep the serversocket (actor based) available to other clients.


4 Responses to Task-based vs actor-based thread usage

  1. huli says:

    You are writing about threads. I have a problem that took me weeks of thinking.

    Context : eclipse RCP /swt

    In SWT there is a UI thread and a way to run tasks there .Display methods asynExec, .syncExec and timerExec (it seems timer exect should be called from the UI thread! ..weird).
    Ok the problem is when you have something like a model that is observable a model provider (jface) and a jface viewer if for every new item in the model you tirgger a notifyObservers and then that adds a Runnable to the UI thread….it works ok for few updates but it starts to kill your application if you have many updates/seconds. So this is the problem. Ideas for solutions?
    thank you.
    I have implemented something but I would liek to heard ideas from you.

  2. Sander Hautvast says:

    Hi Peter,
    you might like this IBM article. It discusses several task based threading alternatives for web based apps

  3. pveentjer says:

    Hi Sander, thanks for the link. I’ll read it this evening.

  4. Sue says:

    I find it hard to understand the difference between these things. Possibly because there is so much middle ground, or possibly because it reminds me of UML which I find totaly obscure and unhelpful!

    How do these two approaches vary in the actual programming?

    Well you have said that task-based approach doesn’t need the thread to hang around, would a client be a good example of this. Similarly an actor based approach is something that needs to always be there, like a server.

    (I am trying to sort this out as I am typing).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: