Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java threads and synchronization
#7
So the loop solution is...

Code:
        while((!player1.hasWon) && (!player2.hasWon)){
            
        }

?

 none of the threads are asleep

At the moment, when I run the code, nothing happens after the threads are started. Both are waiting to be woken up. What wakes them up, I don't know.

I can't call notify or notifyAll from main, which means:
  • Dealer should be a thread and somehow notify player1 when it's done dealing?
  • notify should happen somewhere in the Player thread?
  • go() shouldn't wait and instead, the draw() and discard() methods in CardDeck should be synchronized instead?
Reply


Messages In This Thread
Java threads and synchronization - by Jedward - 2014-02-20, 08:49 PM
Java threads and synchronization - by Locked - 2014-02-20, 09:05 PM
Java threads and synchronization - by Jedward - 2014-02-20, 09:09 PM
Java threads and synchronization - by Locked - 2014-02-20, 09:17 PM
Java threads and synchronization - by Jedward - 2014-02-20, 09:45 PM
Java threads and synchronization - by Locked - 2014-02-20, 09:59 PM
Java threads and synchronization - by Jedward - 2014-02-20, 10:08 PM
Java threads and synchronization - by Locked - 2014-02-20, 10:09 PM
Java threads and synchronization - by happylight - 2014-02-25, 07:07 PM
Java threads and synchronization - by Jedward - 2014-02-27, 08:06 PM
Java threads and synchronization - by happylight - 2014-02-28, 10:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)