Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14931 > unrolled thread
| Started by | Olve <Olve@nowhere.wd.invalid> |
|---|---|
| First post | 2012-05-30 08:18 +0200 |
| Last post | 2012-05-31 09:09 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
A independant pile for communication Olve <Olve@nowhere.wd.invalid> - 2012-05-30 08:18 +0200
Re: A independant pile for communication Martin Gregorie <martin@address-in-sig.invalid> - 2012-05-30 20:53 +0000
Re: A independant pile for communication Olve <Olve@nowhere.wd.invalid> - 2012-05-31 09:09 +0200
| From | Olve <Olve@nowhere.wd.invalid> |
|---|---|
| Date | 2012-05-30 08:18 +0200 |
| Subject | A independant pile for communication |
| Message-ID | <4fc5bb99$0$1706$426a74cc@news.free.fr> |
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
[toc] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2012-05-30 20:53 +0000 |
| Message-ID | <jq61bd$q7r$1@localhost.localdomain> |
| In reply to | #14931 |
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 |
[toc] | [prev] | [next] | [standalone]
| From | Olve <Olve@nowhere.wd.invalid> |
|---|---|
| Date | 2012-05-31 09:09 +0200 |
| Message-ID | <4fc7192b$0$6467$426a74cc@news.free.fr> |
| In reply to | #14945 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web