- Feb 8, 2004
- 12,604
- 15
- 81
Ive been sat staring at the code ive written to make 6 threads of a class randomly add or subtract random numbers to a single shared object of another class, learning about synchronized and locks etc right now. I had no idea in hell why it would never work or just freeze every time. I followed the code through and it all seemed to make perfect sense, everything was there, synchronized the correct methods, notifyAll was in the right place... Problem was this was missing:
Thread thread1 = new Thread(numberMaker1);
Thread thread2 = new Thread(numberMaker2);
Wrap the damn things in a Thread class object if implementing Runnable.... doh! :\
Quite like these moments when i think i just dont get it or ive done it wrong but in fact ive got it right but just forgot something, feels good getting it working in the end. Anyone else get this?
Thread thread1 = new Thread(numberMaker1);
Thread thread2 = new Thread(numberMaker2);
Wrap the damn things in a Thread class object if implementing Runnable.... doh! :\
Quite like these moments when i think i just dont get it or ive done it wrong but in fact ive got it right but just forgot something, feels good getting it working in the end. Anyone else get this?
