A
Andersen
I have two threads created sending messages to eachother (sockets). For
every received message each thread a (not shared) counter, which is
increased for each received message. The counters are output to screen
all the time.
I start both threads. I join on each of the threads (wait for them to
finish). Then I poll each counter to see how many messages was sent.
Problem:
On the screen, the counters are correct (showing 1000), but when I type
an assertion, I get a failure saying that the counters are way lower
than 1000.
Why is this? Does it have to do with java's memory model? I seem to be
accessing old values? If I do a System.out.println(thread1.getCount())
in the parent thread, it all suddenly works.
ps. this is a JUnit testcase.
every received message each thread a (not shared) counter, which is
increased for each received message. The counters are output to screen
all the time.
I start both threads. I join on each of the threads (wait for them to
finish). Then I poll each counter to see how many messages was sent.
Problem:
On the screen, the counters are correct (showing 1000), but when I type
an assertion, I get a failure saying that the counters are way lower
than 1000.
Why is this? Does it have to do with java's memory model? I seem to be
accessing old values? If I do a System.out.println(thread1.getCount())
in the parent thread, it all suddenly works.
ps. this is a JUnit testcase.