Click here to Skip to main content
       

Java

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionsynchronizedmembergeniuspc13 Nov '12 - 14:23 
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,
AnswerRe: synchronized PinmvpRichard MacCutchan13 Nov '12 - 21:17 
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.

AnswerRe: synchronized PinmemberBobJanova13 Nov '12 - 22:41 
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.
GeneralRe: synchronized PinmvpManfred R. Bihy13 Nov '12 - 23:00 
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


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid