A independant pile for communication

Discussion in 'Java' started by Olve, May 30, 2012.

  1. Olve

    Olve Guest

    Dear all,

    I'm trying to have a main class that has an Automaton. This one works
    and studies a problem: that may take a very long time. This automaton
    has a Communicator with Javascript reduced to a minimum. In short:
    ----------------------------------------------------
    public class Communicator{
    JSObject derivedInnerHTML;

    public Communicator (JSObject win){
    this.derivedInnerHTML = (JSObject)
    win.eval("document.getElementById('derived')");
    }

    public void CommDerived(String quoi){
    derivedInnerHTML.setMember("innerHTML", quoi);
    }

    public void CommPlusDerived(String quoi){
    derivedInnerHTML.setMember("innerHTML",
    derivedInnerHTML.getMember("innerHTML") + quoi);
    }
    }
    -----------------------------------------------------------------
    And many other things of the same flavor.

    I would like this communicator to be on another Thread that would
    behave like a pile ... In the automaton I would write sleep(100)
    regularly, and that would do the trick.
    All my trials amounted finally to nothing :(

    I could create a pile of message, create a Thread and have this pile
    being read and displayed in run() with a wait() if the pile is empty and
    a notifyAll() when the pile is fed.
    I'm just wondering whether there is a simpler or more usual way to
    address this issue.
    Many thanks in advance!
    Amities,
    Olivier
    Olve, May 30, 2012
    #1
    1. Advertising

  2. On Wed, 30 May 2012 08:18:01 +0200, Olve wrote:

    > I could create a pile of message, create a Thread and have this pile
    > being read and displayed in run() with a wait() if the pile is empty and
    > a notifyAll() when the pile is fed.


    Using some sort of Queue to hold the messages would be most usual
    approach. Almost anything can be used to add messages: using transient
    threads that just add a message when its presented to your program, e.g.
    via e-mail or via a Socket, and then die is a possibility. The benefit of
    using a Queue is that the thread(s) processing the messages will block
    automatically when the Queue is empty.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
    Martin Gregorie, May 30, 2012
    #2
    1. Advertising

  3. Olve

    Olve Guest

    Le 30/05/2012 22:53, Martin Gregorie a écrit :
    > On Wed, 30 May 2012 08:18:01 +0200, Olve wrote:
    >
    >> I could create a pile of message, create a Thread and have this pile
    >> being read and displayed in run() with a wait() if the pile is empty and
    >> a notifyAll() when the pile is fed.

    >
    > Using some sort of Queue to hold the messages would be most usual
    > approach.


    This is what I resorted to finally. I find that this leads to a somewhat
    convoluted way of programming (in total four objects are defined: the
    queue, the automate (runnable), the runnable that writes and the
    bag-of-holding that contains all of that). Well I should simply get used
    to this way of doing! I'm now seeing that I can use the same queue to
    write several different things at different places, so this solution
    seems ok, if a bit heavy.
    Best,
    A.O.
    Olve, May 31, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gustavo De la Espriella

    How to make an application Database independant

    Gustavo De la Espriella, Feb 3, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    448
    Matt Berther
    Feb 8, 2005
  2. Gustavo De la Espriella
    Replies:
    5
    Views:
    1,064
    Matt Berther
    Feb 8, 2005
  3. Jakob Bieling
    Replies:
    3
    Views:
    332
    Jakob Bieling
    Aug 30, 2004
  4. tshad

    tracking independant hits to page

    tshad, Jul 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    317
    tshad
    Jul 20, 2006
  5. Chris
    Replies:
    5
    Views:
    304
    Roedy Green
    Jun 27, 2008
Loading...

Share This Page