Re: threadpool and ui paint
On 5/13/2014 2:26 AM, Joerg Meier wrote:
On Tue, 13 May 2014 09:35:09 +0200, Philipp Kraus wrote:
class worker {
void run()
{
while (threadruns)
{
for all x = get object from queue
{
calculate x
push x back to the finish queue
SwingUtilities.invokeLater(new Runnable() {
public void run() {
swingJLabelOrWhatever.setText(x);
}
});
}
However, this is broken if 'x' is mutable. You can't mutate (change)
objects that are being accessed by more than one thread. You'll need to
synchronize 'x', and that can be a lot of hassle. The currency
tutorials barely scratch the surface.
I'm going to go out on a limb here and say M. Kraus isn't going to be
able to do that reliably, based on what we've seen from his posts.
I think M. Kraus is going to need to read the language spec, and get a
book called "Java Concurrency in Practice" by Brian Goetz. After
researching those two thoroughly he might be able to design something
workable.
http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html
http://jcip.net.s3-website-us-east-1.amazonaws.com/
- or here paint x -
thread await
for all y = ?K.
}
}