I read now something about what means volatile but didn't understand it well... anyway I think that there is no need to use volatile..it works good for now :P
Amm but now I have one new problem.. my CPU is getting 100% usage becouse of threads..
So what I have:
I'm doing actually a quiz for two players.. When they starts -> the countdown starts and if the countdown ends they lose but if they answer correctly they get another question and countdown has to be restarted. I read that Threads cannot be restarted. They have to be kiilled. But as I try to do that it doesn't work :/
So when the game is started the 2 countdown Thread are started too:
(new Thread(new LCountDown())).start();
(new Thread(new RCountDown())).start();
But when some player answer correctly to one question I should killed the precedent Thread and start the new one...
if (answer == correct){ // Pseudo-code
(new Thread(new RCountDown())).destroy(); // And I just don't know what to do now...
(new Thread(new RCountDown())).start();
}
And I need a solution for these problem becouse in my method Countdown I added a possibilty to chech if time is up
if (c <= 0) {
Time_left.setText("Lose!");
}
But if I don't kill this Thread when someone answer corectly the time will expire anyway becouse the Thread is still running and new countdown will not start because the variable c of the precedent Thread will be still 0.
Anyone understad my problem? :)
Thanks in advance