|
hi guys i have a question, im doing a very simple thread application that increments a value everytime a thread runs, i've got 4 threads running at the same time, but everytime all threads increment the count var, its allways 1 it doesn't change on each thread execution i use synchronized to allow 1 thread increments the var at a time but after all threads die count var outputs same value,
|
|
|
|
|
Please show your code, we cannot guess what may be happening.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
My guess is that you made the counter an instance variable in the thread, so they all have their own copy. But you haven't posted enough to be sure.
|
|
|
|
|
BobJanova wrote: made the counter an instance variable in the thread
That was my guess too!
5+
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|